Keep trailing zeros in Intl.NumberFormat and Intl.PluralRules
for Stage 2 or 2.7
Eemeli Aro, Mozilla
const nf = new Intl.NumberFormat("en");�const pr = new Intl.PluralRules("en");
Currently, trailing zeros are discarded:
nf.format("1.0") === "1";�pr.select("1.0") === "one";
Instead, they should be retained:
nf.format("1.0") === "1.0";�pr.select("1.0") === "other";
If accepted, this proposal would change the internals of Intl.NumberFormat and Intl.PluralRules 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.
16.5.15 Runtime Semantics: StringIntlMV
16.5.16 ToIntlMathematicalValue ( value )
16.5.8 ToRawPrecision ( x, stringDigits, minPrecision, maxPrecision, unsignedRoundingMode )
16.5.9 ToRawFixed ( x, stringDigits, minFraction, �maxFraction, unsignedRoundingMode )
We may want to consider making some changes to the trailingZeroDisplay option, which now has:
It might be possible to change the current default behaviour to be called something like "stripFromString", and to change the "auto" to what's proposed here.
Stage 2?
Stage 2.7 reviewers?
Stage 2.7?
tl;dr
The proposal is a bugfix for Intl.NumberFormat and Intl.PluralRules, which allows trailing zeros in digit strings to be retained. It does not change any public APIs, only the internal behaviour of the number formatter for that specific case. If the current buggy behaviour is shown to have some utility, or if the change proves to be web-incompatible, an option value will be added to the existing trailingZeroDisplay option to address the issue.
The proposal and its specification was presented, and was accepted for Stage 2. RGN and SFC volunteered to act as its Stage 2.7 reviewers, and completed their reviews during the meeting, allowing the proposal to be accepted for Stage 2.7.