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
formatwith no arguments resets to the defaultshortmode. format shortdisplays 4 decimal places in fixed notation for values in [0.001, 10000); uses scientific notation outside that range.format longdisplays 15 decimal places in fixed notation for values in [0.001, 10000); uses 14-decimal scientific notation outside that range.format shortEalways uses scientific notation with 4 decimal places (e.g.,3.1416e+00).format longEalways uses scientific notation with 14 decimal places.format shortGuses the more compact of fixed/scientific notation with 5 significant digits, trimming trailing zeros.format longGuses the more compact of fixed/scientific notation with 15 significant digits, trimming trailing zeros.format ratapproximates values as ratios of small integers using a tolerance of 5×10⁻⁷ (e.g.,355/113for pi).format rationalis accepted as an alias.format hexdisplays the IEEE 754 double-precision hexadecimal bit pattern (e.g.,400921fb54442d18for pi).format compactandformat looseare accepted without error for script compatibility but do not yet change output spacing.- The format setting applies to auto-print results and
dispoutput.fprintf/sprintfuse 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
piExpected output:
ans = 3.1416Long format for full precision
format long
piExpected output:
ans = 3.141592653589793Scientific notation with short precision
format shortE
piExpected output:
ans = 3.1416e+00Scientific notation with full precision
format longE
piExpected output:
ans = 3.14159265358979e+00Rational approximation
format rat
piExpected output:
ans = 355/113Hexadecimal IEEE 754 representation
format hex
piExpected output:
ans = 400921fb54442d18Resetting to default
format
piExpected output:
ans = 3.1416FAQ
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.
Related Io functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how format works, line by line, in Rust.
- View format.rs on GitHub
- Learn how the runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.