MATLAB: How to change the way MATLAB displays the significant digits of floating point numbers
digitdisplayformatMATLABsignificant
How can I change the way MATLAB displays the significant digits of floating point numbers?
I want to adjust how the significant digits of floating point numbers are displayed in the MATLAB Command Window.
Best Answer
The FORMAT function allows users to set the default display method for floating point numbers in MATLAB.
The options for format are:
FORMAT Default. Same as SHORT.
FORMAT SHORTScaled fixed point format with 5 digits.
FORMAT LONGScaled fixed point format with 15 digits.
FORMAT SHORT EFloating point format with 5 digits.
FORMAT LONG EFloating point format with 15 digits.
FORMAT SHORT GBest of fixed or floating point format with 5 digits.
FORMAT LONG GBest of fixed or floating point format with 15 digits.
FORMAT HEXHexadecimal format.
FORMAT + The symbols +, - and blank are printed for positive,
negative and zero elements.Imaginary parts are ignored.
FORMAT BANKFixed format for dollars and cents.
FORMAT RATApproximation by ratio of small integers.
Spacing:
FORMAT COMPACTSuppress extra line-feeds.
FORMAT LOOSEPuts the extra line-feeds back in.
For more information you should see the FORMAT documentation, accessible from MATLAB with the following command:
doc format
Here is a quick example:
>> format short
>> pi
ans =
3.1416
>> format long
>> pi
ans =
3.14159265358979
Currently, it is not possible to specify your own precision in MATLAB. A suggested work-around to this issue would be to use the CEIL and FLOOR functions, in combination with multiplication by magnitudes of 10, to round off to a particular precision.
For example, if you have a variable x = 3.1416, to obtain only three significant digits, you should do the following:
It doesn't. It uses full double-precision floating point numbers to calculate everything. By default it only prints a few decimal places to the screen. You can change this using the command:
Best Answer