Is it possible in matlab to explicitly format the output numbers?

I don't know of a way to specify a global format of the type you want. sprintf('%15.4f', x) or num2str(x, '%15.4f') do what you're looking for, if you don't mind calling them explicitly each time.


According to the Matlab documentation which is available on their website you can use

format shortG

to set the display format for the output to n.4.


According to the documentation it does allow you to format the number.

Also, the formatting is well documented as well.


There are two simple solutions:

  1. using the sprintf function:

    str = sprintf('%.4f', myNumber);

  2. using Java-based formatting, which is much more powerful (more information):

    str = char(java.text.DecimalFormat('#.0000').format(myNumber));


The closest I could come up with, is:

format bank

It will give you no E, and 2 decimal places.

try to read

help format

to look for other options there (I don't use Matlab anymore... switched to Free Software :) )