Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Number Display Format

The format command controls how numbers are displayed in the REPL and script/pipe output. It does not affect computation — all arithmetic is done in f64 (IEEE 754 double precision).

Commands

CommandDescription
formatReset to short (5 significant digits)
format short5 significant digits, auto fixed/scientific
format long15 significant digits, auto fixed/scientific
format shortEAlways scientific, 4 decimal places
format longEAlways scientific, 14 decimal places
format shortGSame as short (MATLAB shortG alias)
format longGSame as long (MATLAB longG alias)
format bankFixed 2 decimal places (currency)
format ratRational approximation p/q
format hexIEEE 754 double-precision bit pattern (16 hex digits)
format +Sign only: + positive, - negative, space for 0
format compactSuppress blank lines between outputs
format looseAdd blank line after every output (default)
format NN decimal places (e.g. format 4)

Examples

>> format short
>> pi
3.1416

>> format long
>> pi
3.14159265358979

>> format shortE
>> pi
3.1416e+00

>> format bank
>> 1/3
0.33

>> format rat
>> pi
355/113

>> format hex
>> 1.0
3FF0000000000000

>> format +
>> [-2 0 5]
- +

>> format 4
>> 1/3
0.3333

Scope

format affects:

  • disp() output
  • Variable assignment display (x = 3.1416)
  • The REPL prompt value

format does not affect fprintf / sprintf — those functions use their own per-call format specifiers (e.g. %f, %e, %.3f).

Automatic scientific notation

In short and long modes, numbers switch to scientific notation when:

  • The exponent is less than −3 (e.g. 0.0011e-03)
  • The exponent is ≥ the number of significant digits

Persistent default

The default precision (used by format N and the startup default) is set in config.toml:

[display]
precision = 10

Note: format hex vs hex

These are different commands:

  • format hex — shows the IEEE 754 raw bit pattern of any floating-point number as 16 uppercase hex digits (e.g. 400921FB54442D18 for pi).
  • hex — switches the display base to hexadecimal for integer values (e.g. 0xFF255 shown as 0xFF).