Number formatting and escaped strings
Explicit formatting methods return arena-owned strings. Existing interpolation
and toString() retain their current display formatting; use these methods when
precision is part of an output format.
| Method | Result |
|---|---|
value.toFixed(digits) |
Fixed decimal places, nearest ties-to-even; digits 0–100 |
value.toShortest() |
Shortest round-trip IEEE f64 decimal, Python repr notation |
value.toShortestF32() |
Round to f32, then shortest decimal that round-trips to that f32 |
integer.toHex(width = 0, prefix = false) |
Lowercase hex, minimum zero-padded digit width 0–1024 |
toShortest() preserves negative zero (-0.0) and emits .0 for integral
fixed-point values. Scientific notation uses a signed exponent with at least
two digits; it is chosen below exponent -4 or at/above 16. For example:
10000000.0, 9.999999974752427e-07, and f32 1e-06. Nonfinite values
produce nan, inf, or -inf; these are not JSON numeric literals.
Numeric formatting is independent of the process locale and restores the
thread’s locale and floating-point rounding mode before returning.
Hex width counts digits only, excluding a minus sign or 0x. Signed negative
integers use a minus sign and magnitude (including the minimum signed long).
Unsigned integers retain their unsigned value. Width never truncates a value.
For space alignment, use existing .padStart(width, " ") or
.padEnd(width, " ") on the returned text.
float value = 1.234567
sys.output(value.toFixed(4)) // 1.2346
int mask = 255
sys.output(mask.toHex(4, true)) // 0x00ff
sys.output(mask.toHex().padStart(8, " "))Double-quoted strings accept \xHH (exactly two hex digits), \uXXXX
(exactly four), and \u{H...} (one to six). Each denotes a Unicode scalar
encoded as UTF-8: \xE9 is é, not the isolated byte E9. Surrogates and
values above U+10FFFF are compile errors. "\x1b[3m" is an ANSI escape
sequence. Escaped braces remain literal and do not start interpolation.
Single-quoted raw strings retain these escape sequences literally.
NUL escapes (\x00, \u0000, \u{0}, or \0) are rejected: strings
currently use a NUL-terminated runtime representation. Use byte[] for binary
data with NULs or arbitrary non-UTF-8 bytes. Formatting renders control
characters with escapes, preserving string values on a format/parse round trip.