RunMat
GitHub

format — Set the numeric display format for console output, controlling how floating-point numbers are shown.

format controls how numeric values appear in the Command Window. The setting is session-wide and persists until changed. Supported numeric precision modes: short (default), long, shortE, longE, shortG, longG, rat, and hex. Spacing modes compact and loose are accepted without error but are not yet implemented. Calling format without arguments resets to short.

How format works

  • Calling format with no arguments resets to the default short mode.
  • format short displays 4 decimal places in fixed notation for values in [0.001, 10000); uses scientific notation outside that range.
  • format long displays 15 decimal places in fixed notation for values in [0.001, 10000); uses 14-decimal scientific notation outside that range.
  • format shortE always uses scientific notation with 4 decimal places (e.g., 3.1416e+00).
  • format longE always uses scientific notation with 14 decimal places.
  • format shortG uses the more compact of fixed/scientific notation with 5 significant digits, trimming trailing zeros.
  • format longG uses the more compact of fixed/scientific notation with 15 significant digits, trimming trailing zeros.
  • format rat approximates values as ratios of small integers using a tolerance of 5×10⁻⁷ (e.g., 355/113 for pi). format rational is accepted as an alias.
  • format hex displays the IEEE 754 double-precision hexadecimal bit pattern (e.g., 400921fb54442d18 for pi).
  • format compact and format loose are accepted without error for script compatibility but do not yet change output spacing.
  • The format setting applies to auto-print results and disp output. fprintf/sprintf use their own explicit format specifiers and are not affected.
  • Mode names are case-insensitive.

How RunMat runs format on the GPU

format does not interact with GPU tensors. It only affects how values are rendered after being gathered to the host for display.

GPU memory and residency

format is a display-only setting with no effect on GPU residency or acceleration.

Examples

Default short format

format short
pi

Expected output:

ans = 3.1416

Long format for full precision

format long
pi

Expected output:

ans = 3.141592653589793

Scientific notation with short precision

format shortE
pi

Expected output:

ans = 3.1416e+00

Scientific notation with full precision

format longE
pi

Expected output:

ans = 3.14159265358979e+00

Rational approximation

format rat
pi

Expected output:

ans = 355/113

Hexadecimal IEEE 754 representation

format hex
pi

Expected output:

ans = 400921fb54442d18

Resetting to default

format
pi

Expected output:

ans = 3.1416

FAQ

Does format affect computation results?

No. format only changes how values are displayed. Internal precision is always IEEE 754 double.

Is the format setting persistent across cells?

Yes. The setting is stored per-session thread and remains active until changed by another format call.

What is the default format?

format short — 4 decimal places in fixed notation, falling back to scientific for very large or very small values.

Does format affect disp?

Yes. disp and auto-print both use the active format setting. fprintf and sprintf use their own explicit format specifiers and ignore this setting.

Are format mode names case-sensitive?

No. format SHORT, format Short, and format short are all equivalent.

What does format rat do for integers?

Integers are displayed as-is without a denominator (e.g., 42 rather than 42/1). format rational is accepted as an alias for format rat.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how format works, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code — faster, on any GPU, with no license required.

  • Simulations that took hours now take minutes. RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed.
  • Start running code in seconds. Open the browser sandbox or download a single binary. No license server, no IT ticket, no setup.
  • A full development environment. GPU-accelerated 2D and 3D plotting, automatic versioning on every save, and a browser IDE you can share with a link.

Getting started · Benchmarks · Pricing

Try RunMat for free

Open the sandbox and start running MATLAB code in seconds. No account required.