Intl Number Format V3
Stage 3 Update
Shane Carr
July 2022 TC39
What is this?
Dozens of feature requests get filed against ECMA-402 every year.
How do we decide which ones to prioritize?
Decision Process Examples
Feature | Stakeholders | CLDR Support | Verdict |
Partial | No | ||
Google, CaixaBank, Community | Yes | Yes |
Parts of This Proposal
green text = changed since Stage 3 presentation
blue text = proposed additional changes
Intl.NumberFormat formatRange: Overview
Main issue: #393
Use cases:
Intl.NumberFormat formatRange: Details
const nf = new Intl.NumberFormat("en-US", {
style: "currency",
currency: "EUR",
signDisplay: "always",
});
nf.formatRange(2.999, 3.001); // "~+€3.00"
Newly approved
Grouping Enum
Main issue: #367
Problem: { useGrouping } takes only true/false, but this is not expressive enough. We know options people want.
Aliases are specified for "auto" and "always" from the existing inputs undefined and true. However, the new values are considered canonical and will be returned in resolvedOptions.
Strategy | One Thousand | Ten Thousand |
"min2" | 1000 | 10,000 |
"auto"�undefined | locale- dependent, usually 1,000 | locale- dependent, usually 10,000 |
"always"�true | 1,000 | 10,000 |
false | 1000 | 10000 |
New Rounding/Precision Options
Main issue: #286
New options:
Rounding Priority (Details: #8)
Problem: what happens when you specify
{ maximumFractionDigits: 2, maximumSignificantDigits: 2 }
You specified two conflicting strategies [example: 4.321]:
New setting roundingPriority resolves this conflict:
Interpret Strings as Decimals
Main issue: #334
We already accept strings, but they get parsed as a Number, losing precision. This part of the proposal will interpret the decimal string at full precision.
How it works: a new type called Intl mathematical value: "a mathematical value together with +∞, -∞, NaN, and -0" [PR is open awaiting review: #82]
const nf = new Intl.NumberFormat("en-US");
const string = "987654321987654321";
nf.format(string);
// Current: "987,654,321,987,654,300"
// Proposed: "987,654,321,987,654,321"
Rounding Modes
Main issue: #419
We will adopt the following 9 rounding modes.
This set encompasses ICU, CSS, and ECMA-262 Math.
Sign Display Negative
Main Issue: #17
We will add a new option signDisplay: "negative". The new option will behave like "auto" except that the sign will not be shown on negative zero.
var nf = new Intl.NumberFormat("en", {� signDisplay: "negative"�});�nf.format(-1.0); // -1�nf.format(-0.0); // 0 (note: "auto" produces "-0" here)�nf.format(0.0); // 0�nf.format(1.0); // 1 (note: "exceptZero" produces "+1" here)
Remaining Open Issues
Remaining Open Issues
All issues have appropriate labels. Remaining open issues that could impact observable behavior:
Discussion