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
<p>An Amount is an object that wraps a numeric value—as a Number, BigInt, or String—together with an optional unit (e.g., mile, kilogram, EUR, JPY, USD-per-mile). One can intuitively understand an Amount as a value that, so to speak, knows what it is measuring.</p>
35
-
<p>When precision options (such as fractionDigits or significantDigits) are applied, or when unit conversion is performed, the numeric value is stored as a <dfn id="dfn-decimal-digit-string">decimal digit string</dfn>, which is a String in |StrDecimalLiteral| form or *"NaN"*. Otherwise, the original JavaScript value type (Number, BigInt, or String) is retained.</p>
35
+
<p>When precision options (such as fractionDigits or significantDigits) are applied, or when unit conversion is performed, finite numeric values are stored as a <dfn id="dfn-decimal-digit-string">decimal digit string</dfn>: a String in |StrDecimalLiteral| form. Non-finite values are stored as the Number values *NaN*, *+∞*<sub>𝔽</sub>, or *-∞*<sub>𝔽</sub>. Otherwise, the original JavaScript value type (Number, BigInt, or String) is retained.</p>
36
36
<p>Rounding a mathematical value is an important part of this spec. When we say <dfn id="dfn-amount-rounding-mode">rounding mode</dfn> in this specification we simply refer to <emu-xref href="#table-intl-rounding-modes">ECMA-402's definition</emu-xref>.</p>
<dd>It returns _v_ rendered in canonical exponential notation: an optional minus sign, a mantissa with one non-zero integer digit (or *"0"*), an optional fractional part, *"e"*, an explicit sign, and an unpadded base-10 exponent. The number of significant digits in the result equals the number of significant digits in _v_. If _v_ is *"NaN"*, *"Infinity"*, or *"-Infinity"*, it is returned unchanged.</dd>
218
+
<dd>It returns _v_ rendered in canonical exponential notation: an optional minus sign, a mantissa with one non-zero integer digit (or *"0"*), an optional fractional part, *"e"*, an explicit sign, and an unpadded base-10 exponent. The number of significant digits in the result equals the number of significant digits in _v_.</dd>
219
219
</dl>
220
220
<emu-alg>
221
221
1. Let _intlMV_ be ! ToIntlMathematicalValue(_v_).
222
222
1. Let _value_ be _intlMV_.[[Value]].
223
-
1. If _value_ is ~not-a-number~, return *"NaN"*.
224
-
1. If _value_ is ~positive-infinity~, return *"Infinity"*.
225
-
1. If _value_ is ~negative-infinity~, return *"-Infinity"*.
226
223
1. Let _digitCount_ be _intlMV_.[[StringDigitCount]].
1. Let _formatter_ be CreateFormatterObject(_roundingMode_, _fractionDigits_, _fractionDigits_, _significantDigits_, _significantDigits_, *undefined*).
367
363
1. Let _intlMV_ be ! ToIntlMathematicalValue(_x_).
368
-
1. Let _formatted_ be FormatNumericToString(_formatter_, _intlMV_.[[Value]], _intlMV_.[[StringDigitCount]]).
369
-
1. Let _value_ be RenderDigitStringInExponentialNotation(_formatted_.[[FormattedString]]).
364
+
1. Let _mv_ be _intlMV_.[[Value]].
365
+
1. If _mv_ is ~positive-infinity~, then
366
+
1. Let _value_ be *+∞*<sub>𝔽</sub>.
367
+
1. Else if _mv_ is ~negative-infinity~, then
368
+
1. Let _value_ be *-∞*<sub>𝔽</sub>.
369
+
1. Else,
370
+
1. Let _formatter_ be CreateFormatterObject(_roundingMode_, _fractionDigits_, _fractionDigits_, _significantDigits_, _significantDigits_, *undefined*).
371
+
1. Let _formatted_ be FormatNumericToString(_formatter_, _mv_, _intlMV_.[[StringDigitCount]]).
372
+
1. Let _value_ be RenderDigitStringInExponentialNotation(_formatted_.[[FormattedString]]).
370
373
1. Let _O_ be OrdinaryObjectCreate(%Amount.prototype%, « [[AmountValue]], [[Unit]] »).
1. Let _convertedValue_ be ? ConvertUnitValue(_sourceValue_, _sourceUnit_, _targetUnit_).
473
-
1. Let _formatter_ be CreateFormatterObject(_roundingMode_, _minFractionDigits_, _maxFractionDigits_, _minSignificantDigits_, _maxSignificantDigits_, _roundingPriority_).
474
-
1. Let _formatted_ be FormatNumericToString(_formatter_, ℝ(_convertedValue_), 0).
475
476
1. Let _result_ be OrdinaryObjectCreate(%Amount.prototype%, « [[AmountValue]], [[Unit]] »).
476
-
1. Set _result_.[[AmountValue]] to RenderDigitStringInExponentialNotation(_formatted_.[[FormattedString]]).
477
+
1. If _convertedValue_ is not finite, then
478
+
1. Set _result_.[[AmountValue]] to _convertedValue_.
479
+
1. Else,
480
+
1. Let _formatter_ be CreateFormatterObject(_roundingMode_, _minFractionDigits_, _maxFractionDigits_, _minSignificantDigits_, _maxSignificantDigits_, _roundingPriority_).
481
+
1. Let _formatted_ be FormatNumericToString(_formatter_, ℝ(_convertedValue_), 0).
482
+
1. Set _result_.[[AmountValue]] to RenderDigitStringInExponentialNotation(_formatted_.[[FormattedString]]).
0 commit comments