Main Content

DisplayFormatOptions

Output display format in Command Window

Description

You can use the format function to return information about the current display format in the Command Window. That information is stored in a DisplayFormatOptions object. The object has two properties: NumericFormat stores the numeric display format, and LineSpacing stores the line spacing display format. You can also call format with a DisplayFormatOptions object as the input argument to restore the display settings saved in that object.

Creation

Create a DisplayFormatOptions object by calling the format function with an output argument.

Properties

expand all

Numeric display format, specified as one of these options.

Style

Result

Example

short

Short, fixed-decimal format with 4 digits after the decimal point. This is the default numeric setting.

3.1416

long

Long, fixed-decimal format with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values.

3.141592653589793

shortE

Short scientific notation with 4 digits after the decimal point.

3.1416e+00

longE

Long scientific notation with 15 digits after the decimal point for double values, and 7 digits after the decimal point for single values.

3.141592653589793e+00

shortG

Short, fixed-decimal format or scientific notation, whichever is more compact, with a total of 5 digits.

3.1416

longG

Long, fixed-decimal format or scientific notation, whichever is more compact, with a total of 15 digits for double values, and 7 digits for single values.

3.14159265358979

shortEng

Short engineering notation (exponent is a multiple of 3) with 4 digits after the decimal point.

3.1416e+000

longEng

Long engineering notation (exponent is a multiple of 3) with 15 significant digits.

3.14159265358979e+000

+

Positive/Negative format with +, -, and blank characters displayed for positive, negative, and zero elements.

+

bank

Currency format with 2 digits after the decimal point.

3.14

hex

Hexadecimal representation of a binary double-precision number.

400921fb54442d18

rational

Ratio of small integers.

355/113

Line spacing display format, specified as compact or loose.

Style

Result

Example

compact

Suppress excess blank lines to show more output on a single screen.

theta = pi/2
theta =
  1.5708

loose

Add blank lines to make output more readable. This is the default setting for line spacing.

theta = pi/2

theta =

  1.5708

Examples

collapse all

Since R2021a

Get the current display format.

fmt = format
fmt = 
  DisplayFormatOptions with properties:

    NumericFormat: "short"
      LineSpacing: "loose"

Since R2021a

Save the current display format and restore it at a later time.

Set the numeric display to shortE and display a 2-by-2 matrix of numeric values.

format shortE
m = [9638573934 37467; 236 574638295]
m = 2×2

    9.6386    0.0000
    0.0000    0.5746

Save the current display format in oldFmt and change the numeric format to longE.

oldFmt = format("longE")
oldFmt = 
  DisplayFormatOptions with properties:

    NumericFormat: "shortE"
      LineSpacing: "loose"

Confirm that the numeric format is now long, scientific notation by redisplaying matrix m.

m
m = 2×2

    9.6386    0.0000
    0.0000    0.5746

Restore the format to its previous state. Redisplay m to confirm that the numeric format is now short, scientific format.

format(oldFmt)
m
m = 2×2

    9.6386    0.0000
    0.0000    0.5746

See Also

Introduced in R2021a