diff --git a/spec.emu b/spec.emu index 4906980..c8eb7e1 100644 --- a/spec.emu +++ b/spec.emu @@ -291,52 +291,37 @@ location: https://github.com/tc39/proposal-amount/

RenderAmountValueWithFractionDigits ( _v_: an Intl mathematical value, - _numDigits_: an integer, - optional _roundingMode_: a rounding mode + _fractionDigits_: an integer ): a String

description
-
It renders the given Intl mathematical value with a given number of fractional digits, rounding, if necessary, using the given rounding mode, which, if missing, is *"halfEven"*.
+
It renders the given Intl mathematical value with a given number of fractional digits
1. If _v_ is ~not-a-number~, return *"NaN"*. 1. If _v_ is ~negative-infinity~, return *"-Infinity"*. 1. If _v_ is ~positive-infinity~, return *"Infinity"*. 1. If _v_ is ~minus-zero~, then - 1. If _numDigits_ < 0, then - 1. Let _exp_ be the unique string representation of -_numDigits_ in base 10 without duplicate leading zeros. - 1. Return the string-concatenation of *"0"*, *"e"*, and _exp_. - 1. Otherwise: - 1. Let _trailingZeroes_ be *"0"* repeated _numDigits_ times. - 1. Let _z_ be *"-0"*. - 1. If _numDigits_ = 0, return _z_. - 1. Otherwise, return the string-concatenation of _z_, *"."* and _trailingZeroes_. - 1. If _roundingMode_ is *undefined*, set _roundingMode_ to *"halfEven"*. + 1. Let _s_ be RenderAmountValueWithFractionDigits(0, _fractionDigits_:). + 1. Return the string-concatenation of *"-"* and _s_. 1. If _v_ < 0, let _prefix_ be *"-"*, else let _prefix_ be "". - 1. If _v_ < 0, then - 1. Set _v_ to -_v_. - 1. Set _roundingMode_ to ReverseRoundingMode(_roundingMode_). - 1. Let _rounded_ be ApplyRoundingModeToPositive(_v_ × 10_numDigits_, _roundingMode_). - 1. Let _e_ be the smallest non-negative integer such that _rounded_ × 10-_numDigits_ is an integer. - 1. Let _s_ be the unique decimal string representation of _rounded_ without duplicate leading zeroes. - 1. If _numDigits_ > _e_, then - 1. If _v_ is an integer, return the string-concatenation of _prefix, _s_, *"."*, and *"0"* repeated _numDigits_ times. - 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _numDigits_ - _e_ times. - 1. If 0 < _numDigits_, then - 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _numDigits_ times. + 1. If _v_ < 0, set _v_ to -_v_. + 1. Let _e_ be the smallest non-negative integer such that _v_ × 10-_e_ is an integer. + 1. If _v_ = 0, let _s_ be *"0"*, else let _s_ be the unique decimal string representation of _v_ that either starts with "0." or does not start with "0". + 1. If _e_ < _fractionDigits_, then + 1. If _v_ is an integer, return the string-concatenation of _prefix_, _s_, *"."*, and *"0"* repeated _fractionDigits_ times. + 1. Otherwise, return the string-concatenation of _prefix_, _s_ and *"0"* repeated _fractionDigits_ - _e_ times. + 1. Else if 0 ≤ _fractionDigits_, then + 1. Return the string-concatenation of _prefix, _s_ and *"0"* repeated _e_ - _fractionDigits_ times. 1. Otherwise: - 1. Assert: _rounded_ is an integer. 1. Let _firstDigit_ be the substring of _s_ from 0 to 1. - 1. Let _p_ be the unique integer such that 1 ≤ _rounded_ × 10_p_ < 10. - 1. Let _n_ be _p_ + _numDigits_. - 1. Assert: _n_ ≥ 0. - 1. Let _exp_ be the unique string representation of _n_ in base-10 without duplicate leading zeros. - 1. If _n_ = 0, then - 1. Return the string-concatenation of _s_, *"e"*, and _exp_. - 1. Otherwise: - 1. Let _remainingDigits_ be the substring of _s_ from 1 to _n_. - 1. Return the string-concatenation of _firstDigit_, *"."*, _remainingDigits_, *"e"*, and _exp_. + 1. If _v_ = 0, let _p_ be 0, else let _p_ be the unique integer such that 1 ≤ _v_ × 10_p_ < 10. + 1. Let _n_ be _p_ + _fractionDigits_. + 1. Assert: _n_ < 0. + 1. Let _exp_ be the unique string representation of -_n_ in base-10 without duplicate leading zeros. + 1. Let _remainingDigits_ be the substring of _s_ from 1 to _n_. + 1. Return the string-concatenation of _firstDigit_, *"."*, _remainingDigits_, *"e"*, and _exp_.