Skip to main content

Module numfmt

Module numfmt 

Source
Expand description

Number.prototype.toLocaleString / BigInt.prototype.toLocaleString with their options argument, in the en-US shape.

This is the ECMA-402 Intl.NumberFormat pipeline restricted to what needs no locale data beyond en-US: the digit options (minimumIntegerDigits, minimum/maximumFractionDigits, minimum/maximumSignificantDigits), useGrouping, and the decimal/percent/currency styles. The locales argument is still ignored (there is no ICU here, so every locale formats as en-US — see BUGS.md). signDisplay and currencyDisplay: "code" are honored; notation, the name/narrowSymbol currency displays and the unit style’s unit label are not modelled.

Rounding is ICU’s: the number’s SHORTEST round-trip decimal form is rounded half away from zero (halfExpand), so (1.005).toLocaleString('en-US', {maximumFractionDigits: 2}) is 1.01 even though the binary value is just below 1.005 — which is where this differs from toFixed.

Enums§

Num
The value being formatted. A BigInt is formatted from its exact digits.

Functions§

to_locale_string
Format x the way x.toLocaleString(locales, opts) does under en-US.