Skip to content

Commit

Permalink
Normative: Add support for cashRounding attribute from CLDR, allowing…
Browse files Browse the repository at this point in the history
… rounding to smallest cash denominations for CAD, CHF, DKK
  • Loading branch information
ben-allen committed Oct 18, 2023
1 parent c2abdfc commit 1428546
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 23 additions & 2 deletions spec/numberformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ <h1>
1. Let _currency_ be _numberFormat_.[[Currency]].
1. Let _currencyPrecision_ be _numberFormat_.[[CurrencyPrecision]].
1. Let _cDigits_ be CurrencyDigits(_currency_, _currencyPrecision_).
1. Let _defaultRoundingIncrement_ be CurrencyRounding(_currency_, _currencyPrecision_).
1. Let _mnfdDefault_ be _cDigits_.
1. Let _mxfdDefault_ be _cDigits_.
1. Else,
1. Let _defaultRoundingIncrement_ be 1.
1. Let _mnfdDefault_ be 0.
1. If _style_ is *"percent"*, then
1. Let _mxfdDefault_ be 0.
1. Else,
1. Let _mxfdDefault_ be 3.
1. Let _notation_ be ? GetOption(_options_, *"notation"*, ~string~, &laquo; *"standard"*, *"scientific"*, *"engineering"*, *"compact"* &raquo;, *"standard"*).
1. Set _numberFormat_.[[Notation]] to _notation_.
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_).
1. Perform ? SetNumberFormatDigitOptions(_numberFormat_, _options_, _mnfdDefault_, _mxfdDefault_, _notation_, _defaultRoundingIncrement_).
1. Let _compactDisplay_ be ? GetOption(_options_, *"compactDisplay"*, ~string~, &laquo; *"short"*, *"long"* &raquo;, *"short"*).
1. Let _defaultUseGrouping_ be *"auto"*.
1. If _notation_ is *"compact"*, then
Expand All @@ -114,6 +116,7 @@ <h1>
_mnfdDefault_: an integer,
_mxfdDefault_: an integer,
_notation_: a String,
_defaultRoundingIncrement_: an integer,
): either a normal completion containing ~unused~ or a throw completion
</h1>
<dl class="header">
Expand All @@ -127,7 +130,7 @@ <h1>
1. Let _mnsd_ be ? Get(_options_, *"minimumSignificantDigits"*).
1. Let _mxsd_ be ? Get(_options_, *"maximumSignificantDigits"*).
1. Set _intlObj_.[[MinimumIntegerDigits]] to _mnid_.
1. Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, 1).
1. Let _roundingIncrement_ be ? GetNumberOption(_options_, *"roundingIncrement"*, 1, 5000, _defaultRoundingIncrement_).
1. If _roundingIncrement_ is not in « 1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000 », throw a *RangeError* exception.
1. Let _roundingMode_ be ? GetOption(_options_, *"roundingMode"*, ~string~, &laquo; *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* &raquo;, *"halfExpand"*).
1. Let _roundingPriority_ be ? GetOption(_options_, *"roundingPriority"*, ~string~, &laquo; *"auto"*, *"morePrecision"*, *"lessPrecision"* &raquo;, *"auto"*).
Expand Down Expand Up @@ -736,6 +739,24 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-currencyrounding" type="abstract operation">
<h1>
CurrencyRounding (
_currency_: a String,
_currencyPrecision_: a String,
): a non-negative integer
</h1>
<dl class="header">
</dl>
<emu-alg>
1. Assert: IsWellFormedCurrencyCode(_currency_) is *true*.
1. Assert: _currency_ is equal to the ASCII-uppercase of _currency_.
1. If the Common Locale Repository supplemental data pertaining to fractional currency values contains an element with _currency_ as the value of its iso4217 attribute, then
1. If _currencyPrecision_ is *"cash"* and the element with _currency_ as the value of its iso4217 attribute has a cashRounding attribute, return the value of that attribute.
1. Return 1.
</emu-alg>
</emu-clause>

<emu-clause id="sec-number-format-functions">
<h1>Number Format Functions</h1>

Expand Down
2 changes: 1 addition & 1 deletion spec/pluralrules.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1>
1. Set _opt_.[[localeMatcher]] to _matcher_.
1. Let _t_ be ? GetOption(_options_, *"type"*, ~string~, &laquo; *"cardinal"*, *"ordinal"* &raquo;, *"cardinal"*).
1. Set _pluralRules_.[[Type]] to _t_.
1. Perform ? SetNumberFormatDigitOptions(_pluralRules_, _options_, 0, 3, *"standard"*).
1. Perform ? SetNumberFormatDigitOptions(_pluralRules_, _options_, 0, 3, *"standard"*, 1).
1. Let _localeData_ be %PluralRules%.[[LocaleData]].
1. Let _r_ be ResolveLocale(%PluralRules%.[[AvailableLocales]], _requestedLocales_, _opt_, %PluralRules%.[[RelevantExtensionKeys]], _localeData_).
1. Set _pluralRules_.[[Locale]] to _r_.[[locale]].
Expand Down

0 comments on commit 1428546

Please sign in to comment.