You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+74-25
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@ nf.formatRangeToParts(3, 5);
62
62
*/
63
63
```
64
64
65
-
When both sides of the range resolve to the same value after rounding, the display will fall back to the approximately sign (see below). The automatic approximately sign will occur only if `signDisplay` is set to `"auto"`; otherwise, the user's requested `signDisplay` will be used.
65
+
When both sides of the range resolve to the same value after rounding, an approximately sign will be added.
66
66
67
67
```javascript
68
68
constnf=newIntl.NumberFormat("en-US", {
@@ -71,37 +71,83 @@ const nf = new Intl.NumberFormat("en-US", {
Currently, Intl.NumberFormat accepts a `{ useGrouping }` option, which accepts a boolean value. However, as reported in the bug thread, there are several options users may want when speficying grouping. This proposal is to add the following strings as valid inputs to `{ useGrouping }`:
85
+
Main Issue: [#3](https://github.com/tc39/proposal-intl-numberformat-v3/issues/3)
86
+
87
+
Currently, Intl.NumberFormat accepts a `{ useGrouping }` option, which accepts a boolean value. However, as reported in the bug thread, there are several options users may want when speficying grouping. This proposal is to make the following be valid inputs to `{ useGrouping }`:
79
88
89
+
-`false`: do not display grouping separators
80
90
-`"min2"`: display grouping separators when there are at least 2 digits in a group; for example, "1000" (first group too small) and "10,000" (now there are at least 2 digits in that group).
81
91
-`"auto"` (default): display grouping separators based on the locale preference, which may also be dependent on the currency. Most locales prefer to use grouping separators.
82
-
-`"always"` (`true`): display grouping separators even if the locale prefers otherwise.
92
+
-`"always"`: display grouping separators even if the locale prefers otherwise.
93
+
-`true`: alias for `"always"`
94
+
-`undefined` (default): alias for `"auto"`
83
95
84
-
Previously considered was an option `"never"` corresponding to the current value `false`. The current proposal does not add that option, because `false` will continue to work, and since non-empty strings are truthy, `if(nf.resolvedOptions().useGrouping)` will continue to work as expected.
96
+
In `resolvedOptions`, either `false` or one of the three strings will be returned. This is an observable behavior change, because currently only the booleans `true` and `false` are returned.
85
97
86
98
## New Rounding/Precision Options ([ECMA-402 #286](https://github.com/tc39/ecma402/issues/286))
Main Issue: [#8](https://github.com/tc39/proposal-intl-numberformat-v3/issues/8
89
101
90
-
Currently, Intl.NumberFormat allows for two rounding strategies: min/max fraction digits, or min/max significant digits. Those strategies cannot be combined.
-`trailingZeroDisplay` = a string expressing the strategy for displaying trailing zeros on whole numbers:
112
+
-`"auto"` = current behavior. Keep trailing zeros according to minimumFractionDigits and minimumSignificantDigits.
113
+
-`"stripIfInteger"` = same as `"auto"`, but remove the fraction digits if they are all zero.
114
+
115
+
### Rounding Priority
116
+
117
+
Currently, Intl.NumberFormat allows for two rounding strategies: min/max fraction digits, or min/max significant digits. Currently, if both min/max fraction digits and min/max significant digits are both specified, significant digit settings take priority and fraction digit settings are ignored.
118
+
119
+
The new option `roundingPriority` specifies two new strategies to resolve mixed fraction digits and significant digits settings. To best express the new strategies, consider the following option bag:
120
+
121
+
```
122
+
{
123
+
maximumFractionDigits: 2,
124
+
maximumSignificantDigits: 2
125
+
}
126
+
```
127
+
128
+
The above options should be interpreted to mean:
129
+
130
+
1. Round the number at the hundredths place
131
+
2. Round the number after the second significant digit
132
+
133
+
Now, consider the number "4.321". `maximumFractionDigits` wants to round at the hundredths place, producing "4.32". However, `maximumSignificantDigits` wants to round after two significant digits, producing "4.3". We therefore have a conflict.
103
134
104
-
The exact semantics of how to allow fraction digits and significant digits to interoperate are being tracked by [#8](https://github.com/tc39/proposal-intl-numberformat-v3/issues/8).
135
+
The new setting `roundingPriority` offers a hint on how to resolve this conflict. There are three options:
136
+
137
+
1.`roundingPriority: "significantDigits"` means that significant digits always win a conflict.
138
+
2.`roundingPriority: "morePrecision"` means that the result with more precision wins a conflict.
139
+
3.`roundingPriority: "lessPrecision"` means that the result with less precision wins a conflict.
140
+
141
+
This resolution algorithm applies separately between the maximum digits settings and the minimum digits settings. So, for example, suppose you had
142
+
143
+
```
144
+
{
145
+
minimumFractionDigits: 2,
146
+
minimumSignificantDigits: 2
147
+
}
148
+
```
149
+
150
+
Consider the input number "1". `minimumFractionDigits` wants to retain trailing zeros up to the hundredths place, producing "1.00", whereas `minimumSignificantDigits` wants to retain only as many as are required to render two significant digits, producing "1.0". We again have a conflict, and the conflict is resolved in the same way.
105
151
106
152
## Interpret Strings as Decimals ([ECMA-402 #334](https://github.com/tc39/ecma402/issues/334))
107
153
@@ -119,18 +165,21 @@ We will reference existing standards for interpreting decimal number strings whe
Intl.NumberFormat always performs "half-up" rounding (for example, if you have 2.5, it gets rounded to 3). However, we understand that there are users and use cases that would benefit from exposing more options for rounding modes.
123
-
124
-
The list of rounding modes could be:
168
+
Main Issue: [#7](https://github.com/tc39/proposal-intl-numberformat-v3/issues/7)
125
169
126
-
1.`"halfUp"` (default)
127
-
2.`"halfEven"`
128
-
3.`"halfDown"`
129
-
4.`"ceiling"`
130
-
5.`"floor"`
131
-
6.`"up"`
132
-
7.`"down"`
170
+
Intl.NumberFormat always performs "half-up" rounding (for example, if you have 2.5, it gets rounded to 3). However, we understand that there are users and use cases that would benefit from exposing more options for rounding modes.
133
171
172
+
The list of rounding modes is proposed to be:
173
+
174
+
1. ceil (toward +∞)
175
+
2. floor (toward -∞)
176
+
3. expand (away from 0)
177
+
4. trunc (toward 0)
178
+
5. halfCeil (ties toward +∞)
179
+
6. halfFloor (ties toward -∞)
180
+
7. halfExpand (ties away from 0; current behavior; default)
181
+
8. halfTrunc (ties toward 0)
182
+
9. halfEven (ties toward the value with even cardinality)
134
183
135
184
## v8 Prototype
136
185
A prototype of the latest spec text can be found in https://chromium-review.googlesource.com/c/v8/v8/+/2336146 w/ the flag --harmony_intl_number_format_v3
0 commit comments