FUNCTION REFERENCE
format
Set how numbers are displayed.
Set how numbers are displayed.
Syntax
formatSyntax
format shortSyntax
format longSyntax
format short gSyntax
format long gSyntax
format short eSyntax
format long eSyntax
format shortEngSyntax
format longEngSyntax
format short engSyntax
format long engSyntax
format compactSyntax
format looseSyntax
format defaultSyntax
format(style)Changes how variables and ans are shown in the Command Window and by disp. short (the default) shows 4 digits after the decimal point, long shows 15 for doubles. shortG and longG show fixed point or e-notation, whichever is more compact, with 5 and 15 significant digits (7 for single) and no common scale factor. shortE and longE show e-notation with 4 and 15 digits after the decimal point (7 for single). shortEng and longEng use an exponent that is a multiple of 3, written 12.3450e+003, with the same number of digits after the decimal point, including for whole numbers. Integer values of up to 9 digits show as integers in every other style. The style can be written longG, longg, long g, format('long','g') or format('longG'), and shortEng, short eng or format('short','eng'), in any letter case. compact drops the blank lines around displayed values; loose puts them back; both keep the numeric style. format or format default resets to short and loose. In short and long, large or small values switch to a common scale factor or to e-notation as MATLAB does. Empty assignment captions follow MATLAB.
Example
format long; x = pi % x = 3.141592653589793Example
format long g; x = pi % x = 3.14159265358979Example
format short e; x = [1 1000.5] % 1.0000e+00 1.0005e+03Example
format('short','g'); x = [1 1000.5 1e-5] % 1 1000.5 1e-05Example
format shortEng; x = 12345 % 12.3450e+003Differences from MATLAB: shortEng and longEng are supported (exponent a multiple of 3, written 12.3450e+003, with 4 or 15 digits after the decimal point, 7 for single). bank, hex, rat and + are not supported yet, and fmt = format does not return the current format. format long uses 7 decimal places for single values.
These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.