|
35 | 35 | </emu-alg>
|
36 | 36 | </emu-clause>
|
37 | 37 | <emu-note>See <emu-xref href="#legacy-constructor"></emu-xref> for the motivation of the normative optional text.</emu-note>
|
| 38 | + |
| 39 | + <emu-clause id="sec-initializenumberformat" aoid="InitializeNumberFormat"> |
| 40 | + <h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1> |
| 41 | + |
| 42 | + <p> |
| 43 | + The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken: |
| 44 | + </p> |
| 45 | + |
| 46 | + <p> |
| 47 | + The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>. |
| 48 | + </p> |
| 49 | + |
| 50 | + <emu-alg> |
| 51 | + 1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). |
| 52 | + 1. Set _options_ to ? CoerceOptionsToObject(_options_). |
| 53 | + 1. Let _opt_ be a new Record. |
| 54 | + 1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, « *"lookup"*, *"best fit"* », *"best fit"*). |
| 55 | + 1. Set _opt_.[[localeMatcher]] to _matcher_. |
| 56 | + 1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*). |
| 57 | + 1. If _numberingSystem_ is not *undefined*, then |
| 58 | + 1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception. |
| 59 | + 1. Set _opt_.[[nu]] to _numberingSystem_. |
| 60 | + 1. Let _localeData_ be %NumberFormat%.[[LocaleData]]. |
| 61 | + 1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_). |
| 62 | + 1. Set _numberFormat_.[[Locale]] to _r_.[[locale]]. |
| 63 | + 1. Set _numberFormat_.[[DataLocale]] to _r_.[[dataLocale]]. |
| 64 | + 1. Set _numberFormat_.[[NumberingSystem]] to _r_.[[nu]]. |
| 65 | + 1. Perform ? SetNumberFormatUnitOptions(_numberFormat_, _options_). |
| 66 | + 1. Let _style_ be _numberFormat_.[[Style]]. |
| 67 | + 1. If _style_ is *"currency"*, then |
| 68 | + 1. Let _currency_ be _numberFormat_.[[Currency]]. |
| 69 | + 1. Let _cDigits_ be CurrencyDigits(_currency_). |
| 70 | + 1. Let _mnfdDefault_ be _cDigits_. |
| 71 | + 1. Let _mxfdDefault_ be _cDigits_. |
| 72 | + 1. Else, |
| 73 | + 1. Let _mnfdDefault_ be 0. |
| 74 | + 1. If _style_ is *"percent"*, then |
| 75 | + 1. Let _mxfdDefault_ be 0. |
| 76 | + 1. Else, |
| 77 | + 1. Let _mxfdDefault_ be 3. |
| 78 | + 1. <ins class="block">Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).</ins> |
| 79 | + 1. <ins class="block">If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.</ins> |
| 80 | + 1. <ins class="block">If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.</ins> |
| 81 | + 1. Let _notation_ be ? GetOption(_options_, *"notation"*, *"string"*, « *"standard"*, *"scientific"*, *"engineering"*, *"compact"* », *"standard"*). |
| 82 | + 1. Set _numberFormat_.[[Notation]] to _notation_. |
| 83 | + 1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_). |
| 84 | + 1. <ins class="block">If _roundingIncrement_ is not 1, then</ins> |
| 85 | + 1. <ins class="block">If _numberFormat_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.</ins> |
| 86 | + 1. <ins class="block">If _numberFormat_.[[MaximumFractionDigits]] is not equal to _numberFormat_.[[MinimumFractionDigits]], throw a *RangeError* exception.</ins> |
| 87 | + 1. <ins class="block">Set _numberFormat_.[[RoundingIncrement]] to _roundingIncrement_.</ins> |
| 88 | + 1. <ins class="block">Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, *"string"*, « *"auto"*, *"stripIfInteger"* », *"auto"*).</ins> |
| 89 | + 1. <ins class="block">Set _numberFormat_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.</ins> |
| 90 | + 1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, *"string"*, « *"short"*, *"long"* », *"short"*). |
| 91 | + 1. <ins class="block">Let _defaultUseGrouping_ be *"auto"*.</ins> |
| 92 | + 1. If _notation_ is *"compact"*, then |
| 93 | + 1. Set _numberFormat_.[[CompactDisplay]] to _compactDisplay_. |
| 94 | + 1. <ins class="block">Set _defaultUseGrouping_ to *"min2"*.</ins> |
| 95 | + 1. Let _useGrouping_ be ? Get<ins>StringOrBoolean</ins>Option(_options_, *"useGrouping"*, <del>*"boolean"*, *undefined*, *true*</del> <ins>« *"min2"*, *"auto"*, *"always"* », *"always"*, *false*, _defaultUseGrouping_</ins>). |
| 96 | + 1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_. |
| 97 | + 1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, *"string"*, « *"auto"*, *"never"*, *"always"*, *"exceptZero"*<ins>, *"negative"*</ins> », *"auto"*). |
| 98 | + 1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_. |
| 99 | + 1. <ins class="block">Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, *"string"*, « *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* », *"halfExpand"*).</ins> |
| 100 | + 1. <ins class="block">Set _numberFormat_.[[RoundingMode]] to _roundingMode_.</ins> |
| 101 | + 1. Return _numberFormat_. |
| 102 | + </emu-alg> |
| 103 | + </emu-clause> |
38 | 104 | </emu-clause>
|
39 | 105 |
|
40 | 106 | <emu-clause id="sec-numberformat-abstracts">
|
|
119 | 185 | </emu-alg>
|
120 | 186 | </emu-clause>
|
121 | 187 |
|
122 |
| - <emu-clause id="sec-initializenumberformat" aoid="InitializeNumberFormat"> |
123 |
| - <h1>InitializeNumberFormat ( _numberFormat_, _locales_, _options_ )</h1> |
124 |
| - |
125 |
| - <p> |
126 |
| - The abstract operation InitializeNumberFormat accepts the arguments _numberFormat_ (which must be an object), _locales_, and _options_. It initializes _numberFormat_ as a NumberFormat object. The following steps are taken: |
127 |
| - </p> |
128 |
| - |
129 |
| - <p> |
130 |
| - The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>. |
131 |
| - </p> |
132 |
| - |
133 |
| - <emu-alg> |
134 |
| - 1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). |
135 |
| - 1. Set _options_ to ? CoerceOptionsToObject(_options_). |
136 |
| - 1. Let _opt_ be a new Record. |
137 |
| - 1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, « *"lookup"*, *"best fit"* », *"best fit"*). |
138 |
| - 1. Set _opt_.[[localeMatcher]] to _matcher_. |
139 |
| - 1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, *"string"*, *undefined*, *undefined*). |
140 |
| - 1. If _numberingSystem_ is not *undefined*, then |
141 |
| - 1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception. |
142 |
| - 1. Set _opt_.[[nu]] to _numberingSystem_. |
143 |
| - 1. Let _localeData_ be %NumberFormat%.[[LocaleData]]. |
144 |
| - 1. Let _r_ be ResolveLocale(%NumberFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %NumberFormat%.[[RelevantExtensionKeys]], _localeData_). |
145 |
| - 1. Set _numberFormat_.[[Locale]] to _r_.[[locale]]. |
146 |
| - 1. Set _numberFormat_.[[DataLocale]] to _r_.[[dataLocale]]. |
147 |
| - 1. Set _numberFormat_.[[NumberingSystem]] to _r_.[[nu]]. |
148 |
| - 1. Perform ? SetNumberFormatUnitOptions(_numberFormat_, _options_). |
149 |
| - 1. Let _style_ be _numberFormat_.[[Style]]. |
150 |
| - 1. If _style_ is *"currency"*, then |
151 |
| - 1. Let _currency_ be _numberFormat_.[[Currency]]. |
152 |
| - 1. Let _cDigits_ be CurrencyDigits(_currency_). |
153 |
| - 1. Let _mnfdDefault_ be _cDigits_. |
154 |
| - 1. Let _mxfdDefault_ be _cDigits_. |
155 |
| - 1. Else, |
156 |
| - 1. Let _mnfdDefault_ be 0. |
157 |
| - 1. If _style_ is *"percent"*, then |
158 |
| - 1. Let _mxfdDefault_ be 0. |
159 |
| - 1. Else, |
160 |
| - 1. Let _mxfdDefault_ be 3. |
161 |
| - 1. <ins class="block">Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).</ins> |
162 |
| - 1. <ins class="block">If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.</ins> |
163 |
| - 1. <ins class="block">If _roundingIncrement_ is not 1, set _mxfdDefault_ to _mnfdDefault_.</ins> |
164 |
| - 1. Let _notation_ be ? GetOption(_options_, *"notation"*, *"string"*, « *"standard"*, *"scientific"*, *"engineering"*, *"compact"* », *"standard"*). |
165 |
| - 1. Set _numberFormat_.[[Notation]] to _notation_. |
166 |
| - 1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_). |
167 |
| - 1. <ins class="block">If _roundingIncrement_ is not 1, then</ins> |
168 |
| - 1. <ins class="block">If _numberFormat_.[[RoundingType]] is not ~fractionDigits~, throw a *TypeError* exception.</ins> |
169 |
| - 1. <ins class="block">If _numberFormat_.[[MaximumFractionDigits]] is not equal to _numberFormat_.[[MinimumFractionDigits]], throw a *RangeError* exception.</ins> |
170 |
| - 1. <ins class="block">Set _numberFormat_.[[RoundingIncrement]] to _roundingIncrement_.</ins> |
171 |
| - 1. <ins class="block">Let _trailingZeroDisplay_ be ? GetOption(_options_, *"trailingZeroDisplay"*, *"string"*, « *"auto"*, *"stripIfInteger"* », *"auto"*).</ins> |
172 |
| - 1. <ins class="block">Set _numberFormat_.[[TrailingZeroDisplay]] to _trailingZeroDisplay_.</ins> |
173 |
| - 1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, *"string"*, « *"short"*, *"long"* », *"short"*). |
174 |
| - 1. <ins class="block">Let _defaultUseGrouping_ be *"auto"*.</ins> |
175 |
| - 1. If _notation_ is *"compact"*, then |
176 |
| - 1. Set _numberFormat_.[[CompactDisplay]] to _compactDisplay_. |
177 |
| - 1. <ins class="block">Set _defaultUseGrouping_ to *"min2"*.</ins> |
178 |
| - 1. Let _useGrouping_ be ? Get<ins>StringOrBoolean</ins>Option(_options_, *"useGrouping"*, <del>*"boolean"*, *undefined*, *true*</del> <ins>« *"min2"*, *"auto"*, *"always"* », *"always"*, *false*, _defaultUseGrouping_</ins>). |
179 |
| - 1. Set _numberFormat_.[[UseGrouping]] to _useGrouping_. |
180 |
| - 1. Let _signDisplay_ be ? GetOption(_options_, *"signDisplay"*, *"string"*, « *"auto"*, *"never"*, *"always"*, *"exceptZero"*<ins>, *"negative"*</ins> », *"auto"*). |
181 |
| - 1. Set _numberFormat_.[[SignDisplay]] to _signDisplay_. |
182 |
| - 1. <ins class="block">Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, *"string"*, « *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* », *"halfExpand"*).</ins> |
183 |
| - 1. <ins class="block">Set _numberFormat_.[[RoundingMode]] to _roundingMode_.</ins> |
184 |
| - 1. Return _numberFormat_. |
185 |
| - </emu-alg> |
186 |
| - </emu-clause> |
187 |
| - |
188 | 188 | <emu-clause id="sec-currencydigits" aoid="CurrencyDigits">
|
189 | 189 | <h1>CurrencyDigits ( _currency_ )</h1>
|
190 | 190 |
|
|
0 commit comments