FUNCTION REFERENCE

format

Set how numbers are displayed.

Set how numbers are displayed.

Syntax

format

Syntax

format short

Syntax

format long

Syntax

format short g

Syntax

format long g

Syntax

format short e

Syntax

format long e

Syntax

format shortEng

Syntax

format longEng

Syntax

format short eng

Syntax

format long eng

Syntax

format compact

Syntax

format loose

Syntax

format default

Syntax

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.141592653589793

Example

format long g; x = pi   % x = 3.14159265358979

Example

format short e; x = [1 1000.5]   % 1.0000e+00   1.0005e+03

Example

format('short','g'); x = [1 1000.5 1e-5]   % 1   1000.5   1e-05

Example

format shortEng; x = 12345   % 12.3450e+003

Differences 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.