@formatjs/intl-numberformat 4.2.1 → 4.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/dist/polyfill-with-locales-for-test262.min.js +51 -30
- package/dist/polyfill-with-locales-for-test262.min.js.map +1 -1
- package/dist/umd/intl-numberformat.js +39 -30
- package/dist/umd/intl-numberformat.js.map +1 -1
- package/dist/umd/intl-numberformat.min.js +1 -1
- package/dist/umd/intl-numberformat.min.js.map +1 -1
- package/dist/umd/polyfill-with-locales.js +51 -30
- package/dist/umd/polyfill-with-locales.js.map +1 -1
- package/dist/umd/polyfill.js +39 -30
- package/dist/umd/polyfill.js.map +1 -1
- package/package.json +5 -5
- package/dist/currency-digits.json +0 -1
- package/dist/ilnd-numbers.json +0 -1
- package/dist/units-constants.d.ts +0 -2
- package/dist/units-constants.d.ts.map +0 -1
- package/dist/units-constants.js +0 -3
- package/dist/units-constants.js.map +0 -1
- package/lib/currency-digits.json +0 -1
- package/lib/ilnd-numbers.json +0 -1
- package/lib/units-constants.d.ts +0 -2
- package/lib/units-constants.d.ts.map +0 -1
- package/lib/units-constants.js +0 -1
- package/lib/units-constants.js.map +0 -1
- package/src/currency-digits.json +0 -1
- package/src/ilnd-numbers.json +0 -1
- package/src/units-constants.ts +0 -4
package/dist/umd/polyfill.js
CHANGED
|
@@ -252,13 +252,7 @@
|
|
|
252
252
|
*/
|
|
253
253
|
function toRawFixed(x, minFraction, maxFraction) {
|
|
254
254
|
var f = maxFraction;
|
|
255
|
-
var n;
|
|
256
|
-
{
|
|
257
|
-
var exactSolve = x * Math.pow(10, f);
|
|
258
|
-
var roundDown = Math.floor(exactSolve);
|
|
259
|
-
var roundUp = Math.ceil(exactSolve);
|
|
260
|
-
n = exactSolve - roundDown < roundUp - exactSolve ? roundDown : roundUp;
|
|
261
|
-
}
|
|
255
|
+
var n = Math.round(x * Math.pow(10, f));
|
|
262
256
|
var xFinal = n / Math.pow(10, f);
|
|
263
257
|
// n is a positive integer, but it is possible to be greater than 1e21.
|
|
264
258
|
// In such case we will go the slow path.
|
|
@@ -269,13 +263,9 @@
|
|
|
269
263
|
}
|
|
270
264
|
else {
|
|
271
265
|
m = n.toString();
|
|
272
|
-
var
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
m =
|
|
276
|
-
m.substring(0, idx1) +
|
|
277
|
-
m.substring(idx1 + 1, idx2) +
|
|
278
|
-
repeat('0', exponent - (idx2 - idx1 - 1));
|
|
266
|
+
var _a = m.split('e'), mantissa = _a[0], exponent = _a[1];
|
|
267
|
+
m = mantissa.replace('.', '');
|
|
268
|
+
m = m + repeat('0', Math.max(+exponent - m.length + 1, 0));
|
|
279
269
|
}
|
|
280
270
|
var int;
|
|
281
271
|
if (f !== 0) {
|
|
@@ -315,23 +305,38 @@
|
|
|
315
305
|
xFinal = 0;
|
|
316
306
|
}
|
|
317
307
|
else {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
308
|
+
var xToString = x.toString();
|
|
309
|
+
// If xToString is formatted as scientific notation, the number is either very small or very
|
|
310
|
+
// large. If the precision of the formatted string is lower that requested max precision, we
|
|
311
|
+
// should still infer them from the formatted string, otherwise the formatted result might have
|
|
312
|
+
// precision loss (e.g. 1e41 will not have 0 in every trailing digits).
|
|
313
|
+
var xToStringExponentIndex = xToString.indexOf('e');
|
|
314
|
+
var _a = xToString.split('e'), xToStringMantissa = _a[0], xToStringExponent = _a[1];
|
|
315
|
+
var xToStringMantissaWithoutDecimalPoint = xToStringMantissa.replace('.', '');
|
|
316
|
+
if (xToStringExponentIndex >= 0 &&
|
|
317
|
+
xToStringMantissaWithoutDecimalPoint.length <= p) {
|
|
318
|
+
e = +xToStringExponent;
|
|
319
|
+
m =
|
|
320
|
+
xToStringMantissaWithoutDecimalPoint +
|
|
321
|
+
repeat('0', p - xToStringMantissaWithoutDecimalPoint.length);
|
|
322
|
+
xFinal = x;
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
e = getMagnitude(x);
|
|
326
|
+
var decimalPlaceOffset = e - p + 1;
|
|
327
|
+
// n is the integer containing the required precision digits. To derive the formatted string,
|
|
328
|
+
// we will adjust its decimal place in the logic below.
|
|
329
|
+
var n = Math.round(adjustDecimalPlace(x, decimalPlaceOffset));
|
|
330
|
+
// The rounding caused the change of magnitude, so we should increment `e` by 1.
|
|
331
|
+
if (adjustDecimalPlace(n, p - 1) >= 10) {
|
|
332
|
+
e = e + 1;
|
|
333
|
+
// Divide n by 10 to swallow one precision.
|
|
334
|
+
n = Math.floor(n / 10);
|
|
335
|
+
}
|
|
336
|
+
m = n.toString();
|
|
337
|
+
// Equivalent of n * 10 ** (e - p + 1)
|
|
338
|
+
xFinal = adjustDecimalPlace(n, p - 1 - e);
|
|
328
339
|
}
|
|
329
|
-
// See: https://tc39.es/ecma262/#sec-numeric-types-number-tostring
|
|
330
|
-
// No need to worry about scientific notation because it only happens for values >= 1e21,
|
|
331
|
-
// which has 22 significant digits. So it will at least be divided by 10 here to bring the
|
|
332
|
-
// value back into non-scientific-notation range.
|
|
333
|
-
m = n.toString();
|
|
334
|
-
xFinal = n * Math.pow(10, (e - p + 1));
|
|
335
340
|
}
|
|
336
341
|
var int;
|
|
337
342
|
if (e >= p - 1) {
|
|
@@ -357,6 +362,10 @@
|
|
|
357
362
|
}
|
|
358
363
|
}
|
|
359
364
|
return { formattedString: m, roundedNumber: xFinal, integerDigitsCount: int };
|
|
365
|
+
// x / (10 ** magnitude), but try to preserve as much floating point precision as possible.
|
|
366
|
+
function adjustDecimalPlace(x, magnitude) {
|
|
367
|
+
return magnitude < 0 ? x * Math.pow(10, -magnitude) : x / Math.pow(10, magnitude);
|
|
368
|
+
}
|
|
360
369
|
}
|
|
361
370
|
function repeat(s, times) {
|
|
362
371
|
if (typeof s.repeat === 'function') {
|