Champion: Eemeli Aro
Stage: 1
Presentations:
- For Stage 1 (2025.05)
Trailing zeros are important when formatting numbers or selecting their plural categories, and should be retained when included in a numeric string input value.
Currently, trailing zeros are discarded:
const nf = new Intl.NumberFormat("en");
nf.format("1.0") === "1";
const pr = new Intl.PluralRules("en");
pr.select("1.0") === "one";
Instead, they should be retained:
const nf = new Intl.NumberFormat("en");
nf.format("1.0") === "1.0";
const pr = new Intl.PluralRules("en");
pr.select("1.0") === "other";
Currently, Intl.NumberFormat and Intl.PluralRules accept numeric strings as input, converting such internally to an Intl Mathematical Value with arbitrary decimal precision.
If accepted, this proposal would change the internals of these interfaces
such that trailing zeros would be retained,
and included in the formatted or selected value.
The treatment of Number or BigInt values would not change,
and options such as maximumFractionDigits
would still work as before:
const nf = new Intl.NumberFormat('en', { minimumFractionDigits: 1 });
nf.format('1') === '1.0'
nf.format('1.00') === '1.00'
nf.format('1.0000') === '1.000'
// maximumFractionDigits default is 3.
The treatment of numeric string values was previously changed in 2023 as a part of the Intl.NumberFormat V3 proposal, before which they were parsed into lower-precision Number values.
The Decimal proposal is looking to introduce
a numeric type capable of representing values with up to 34 decimal places of precision,
along with a separate representation of the value's precision via Decimal.Amount
or some other representation.
Currently, the effective limits for the precision of Intl.NumberFormat and Intl.PluralRules
are around 300 decimal places for the integer part, and 100 places for the fraction part.
The maximum limit for the fraction precision was increased in 2023 from 20 to 100 in ECMA-402 PR #786.
A numerical string representation of a Number with trailing zeros is available as Number.prototype.toPrecision
:
(42).toPrecision(4) === "42.00"
(4200).toPrecision(2) === "4.2e+3"