format
Sets how numbers are displayed in output.
Category: Language Fundamentals > Entering Commands
Syntax
format
Returns to the default, short.
format long
Shows about 15 significant digits for doubles and 7 for singles.
format short
Shows 5 significant digits, such as 3.1416.
format short e
Other styles are long e, short g, long g, bank, rat, hex and +.
Description
format changes only how values are printed, never how they are stored or computed. It affects results shown without a semicolon and disp, but not fprintf or num2str, which use their own conversion rules.
The setting stays until changed again. Integer types are not affected.
Input arguments
style- Name of the display style, such as
short,long,short e,long e,short g,long g,bank,rat,hexor+. It can also be given asformat('long').
Example
Short and long
format long
pi
single(pi)
format short
pi
Output
ans = 3.141592653589793
ans = single
3.1415927
ans = 3.1416
Notes
compact and loose are accepted, but the display is always compact. Complex numbers under format rat are spaced differently from MATLAB.