MATLAB Answers


round off in matlab

Asked by dav
on 5 Apr 2013


I am running a large simulation in matlab. I have noticed that matlab rounds off after 4 decimal places and this affects my results.

Is there a way to give a command at the beginning of the program so that matlab does the round off after about 10 decimal places?


  1 Comment

Matlab's 'double' does not round off after four decimals as far as the actual computations are concerned. It is always accurate to about 16 significant decimal digits. It's only the display of its results that is given to four digits if you are using format short. It is important to understand the difference.

Try this experiment.

 format short
 x = pi^2
 fprintf('x = %19.16f\n',x)

The second display is accurate to 16 places which means that this was the accuracy of the original computation. The 'short' format only displayed four of the significant digits.


No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek
on 5 Apr 2013
 Accepted answer

 format long


on 5 Apr 2013


should you put a ";" after this command?

And is there a way to specify the number of decimal places?


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!