I was wondering how to use command to set up displaying with n decimal places in Matlab?
Must n be restricted to some predetermined numbers? Or one can just specify any for n?
Thanks and regards!
This question is related to
matlab
number-formatting
i use like tim say sprintf('%0.6f', x)
, it's a string then i change it to number by using command str2double(x)
.
You can convert a number to a string with n decimal places using the SPRINTF command:
>> x = 1.23; >> sprintf('%0.6f', x) ans = 1.230000 >> x = 1.23456789; >> sprintf('%0.6f', x) ans = 1.234568
This site might help you out with all of that:
Source: Stackoverflow.com