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
[spec] Use fractionDigits/significantDigits in convertTo, allow Number values
Aligns Amount.prototype.convertTo with the README updates from #101:
replaces the min/max fraction/significant digit options and roundingPriority
with the constructor-style fractionDigits and significantDigits (mutually
exclusive, throwing RangeError if both are set). When neither precision
option is supplied — or the converted value is non-finite — the resulting
Amount is now Number-backed rather than always String-backed.
): either a normal completion containing a Record with fields [[MinimumFractionDigits]] (a non-negative integer or *undefined*), [[MaximumFractionDigits]] (a non-negative integer or *undefined*), [[RoundingMode]] (a <emu-xref href="#dfn-amount-rounding-mode">rounding mode</emu-xref>), [[RoundingPriority]] (a String), [[MinimumSignificantDigits]] (a positive integer or *undefined*), [[MaximumSignificantDigits]] (a positive integer or *undefined*), [[Locale]] (a String or *undefined*), [[Usage]] (a String or *undefined*), and [[Unit]] (a String or *undefined*) or a throw completion
109
+
): either a normal completion containing a Record with fields [[FractionDigits]] (a non-negative integer or *undefined*), [[RoundingMode]] (a <emu-xref href="#dfn-amount-rounding-mode">rounding mode</emu-xref>), [[SignificantDigits]] (a positive integer or *undefined*), and [[Unit]] (a String or *undefined*) or a throw completion
110
110
</h1>
111
111
<dl class="header">
112
112
<dt>description</dt>
113
113
<dd>It validates the given _options_ (an ECMAScript object) for converting an Amount to another Amount and returns a Record with slots set to appropriate marthematical values (or *undefined*).</dd>
114
114
</dl>
115
115
<emu-alg>
116
116
1. Let _opts_ be ? GetOptionsObject(_opts_).
117
-
1. Let _minFractionDigits_ be ? GetOption(_opts_, *"minimumFractionDigits"*, ~number~, ~empty~, *undefined*).
118
-
1. Let _maxFractionDigits_ be ? GetOption(_opts_, *"maximumFractionDigits"*, ~number~, ~empty~, *undefined*).
117
+
1. Let _fractionDigits_ be ? GetOption(_opts_, *"fractionDigits"*, ~number~, ~empty~, *undefined*).
119
118
1. Let _roundingMode_ be ? GetOption(_opts_, *"roundingMode"*, ~string~, « *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* », *"halfEven"*).
120
-
1. Let _roundingPriority_ be ? GetOption(_opts_, *"roundingPriority"*, ~string~, ~empty~, *undefined*).
121
-
1. Let _minSignificantDigits_ be ? GetOption(_opts_, *"minimumSignificantDigits"*, ~number~, ~empty~, *undefined*).
122
-
1. Let _maxSignificantDigits_ be ? GetOption(_opts_, *"maximumSignificantDigits"*, ~number~, ~empty~, *undefined*).
119
+
1. Let _significantDigits_ be ? GetOption(_opts_, *"significantDigits"*, ~number~, ~empty~, *undefined*).
123
120
1. Let _unit_ be ? GetOption(_opts_, *"unit"*, ~string~, ~empty~, *undefined*).
124
-
1. If _minFractionDigits_ is not *undefined*, then
125
-
1. If _minFractionDigits_ is not an integral Number, throw a *RangeError* exception.
126
-
1. Set _minFractionDigits_ to ℝ(_minFractionDigits_).
127
-
1. If _minFractionDigits_ is not in the inclusive interval from 0 to 100, throw a *RangeError* exception.
128
-
1. If _maxFractionDigits_ is not *undefined*, then
129
-
1. If _maxFractionDigits_ is not an integral Number, throw a *RangeError* exception.
130
-
1. Set _maxFractionDigits_ to ℝ(_maxFractionDigits_).
131
-
1. If _maxFractionDigits_ is not in the inclusive interval from 0 to 100, throw a *RangeError* exception.
132
-
1. If _minFractionDigits_ is not *undefined* and _maxFractionDigits_ is not *undefined* and _minFractionDigits_ > _maxFractionDigits_, throw a *RangeError* exception.
133
-
1. If _minSignificantDigits_ is not *undefined*, then
134
-
1. If _minSignificantDigits_ is not an integral Number, throw a *RangeError* exception.
135
-
1. Set _minSignificantDigits_ to ℝ(_minSignificantDigits_).
136
-
1. If _minSignificantDigits_ is not in the inclusive interval from 1 to 21, throw a *RangeError* exception.
137
-
1. If _maxSignificantDigits_ is not *undefined*, then
138
-
1. If _maxSignificantDigits_ is not an integral Number, throw a *RangeError* exception.
139
-
1. Set _maxSignificantDigits_ to ℝ(_maxSignificantDigits_).
140
-
1. If _maxSignificantDigits_ is not in the inclusive interval from 1 to 21, throw a *RangeError* exception.
141
-
1. If _minSignificantDigits_ is not *undefined* and _maxSignificantDigits_ is not *undefined* and _minSignificantDigits_ > _maxSignificantDigits_, throw a *RangeError* exception.
121
+
1. If _fractionDigits_ is not *undefined*, then
122
+
1. If _significantDigits_ is not *undefined*, throw a *RangeError* exception.
123
+
1. If _fractionDigits_ is not an integral Number, throw a *RangeError* exception.
124
+
1. Set _fractionDigits_ to ℝ(_fractionDigits_).
125
+
1. If _fractionDigits_ is not in the inclusive interval from 0 to 100, throw a *RangeError* exception.
126
+
1. Else if _significantDigits_ is not *undefined*, then
127
+
1. If _significantDigits_ is not an integral Number, throw a *RangeError* exception.
128
+
1. Set _significantDigits_ to ℝ(_significantDigits_).
129
+
1. If _significantDigits_ is not in the inclusive interval from 1 to 21, throw a *RangeError* exception.
142
130
1. If _unit_ is the empty String, throw a *RangeError* exception.
143
-
1. Return the Record { [[MinimumFractionDigits]]: _minFractionDigits_, [[MaximumFractionDigits]]: _maxFractionDigits_, [[MinimumSignificantDigits]]: _minSignificantDigits_, [[MaximumSignificantDigits]]: _maxSignificantDigits_, [[RoundingMode]]: _roundingMode_, [[RoundingPriority]]: _roundingPriority_, [[Unit]]: _unit_ }.
131
+
1. Return the Record { [[FractionDigits]]: _fractionDigits_, [[RoundingMode]]: _roundingMode_, [[SignificantDigits]]: _significantDigits_, [[Unit]]: _unit_ }.
1. Let _convertedValue_ be ? ConvertUnitValue(_sourceValue_, _sourceUnit_, _targetUnit_).
406
-
1. Let _formatter_ be CreateFormatterObject(_roundingMode_, _minFractionDigits_, _maxFractionDigits_, _minSignificantDigits_, _maxSignificantDigits_, _roundingPriority_).
407
-
1. Let _formatted_ be FormatNumericToString(_formatter_, ℝ(_convertedValue_), 0).
408
391
1. Let _result_ be OrdinaryObjectCreate(%Amount.prototype%, « [[AmountValue]], [[Unit]] »).
409
-
1. Set _result_.[[AmountValue]] to _formatted_.[[FormattedString]].
392
+
1. If _convertedValue_ is finite and (_fractionDigits_ is not *undefined* or _significantDigits_ is not *undefined*), then
393
+
1. Let _formatter_ be CreateFormatterObject(_roundingMode_, _fractionDigits_, _fractionDigits_, _significantDigits_, _significantDigits_, *undefined*).
394
+
1. Let _formatted_ be FormatNumericToString(_formatter_, ℝ(_convertedValue_), 0).
395
+
1. Set _result_.[[AmountValue]] to _formatted_.[[FormattedString]].
396
+
1. Else,
397
+
1. Set _result_.[[AmountValue]] to _convertedValue_.
0 commit comments