Skip to content

Awkward rounding behavior when currencies are used #239

@sffc

Description

@sffc

The spec reads:

Section 11.1.2:

Let cDigits be CurrencyDigits(currency).
...
Let mnfdDefault be cDigits.
Let mxfdDefault be cDigits.
...
Perform ? SetNumberFormatDigitOptions(numberFormat, options, mnfdDefault, mxfdDefault).

Section 11.1.1:

Let mnfd be ? GetNumberOption(options, "minimumFractionDigits", 0, 20, mnfdDefault).
Let mxfdActualDefault be max( mnfd, mxfdDefault ).
Let mxfd be ? GetNumberOption(options, "maximumFractionDigits", mnfd, 20, mxfdActualDefault).

Fine. So say I use a currency that sets mnfdDefault=2 and mxfdDefault=2. However, I want to override the rounding so that I get integer rounding (no fraction digits). I try to set options.maximumFractionDigits to 0.

new Intl.NumberFormat("en", { style: "currency", currency: "EUR", maximumFractionDigits: 0 });

RangeError!

VM61:1 Uncaught RangeError: maximumFractionDigits value is out of range.
at new NumberFormat (native)
at :1:1

Although consistent with the spec, this is bad behavior for a number of reasons:

  1. Currency default fraction digits could change over time (unlikely but possible), meaning different versions of CLDR could trigger the exception but not others.
  2. It is just bad behavior from a user's perspective.

I would like to fix up the spec so that RangeError is thrown only when the user's minimumFractionDigits and maximumFractionDigits are in conflict with each other, not when they are in conflict with some random CLDR currency rounding data.

Metadata

Metadata

Assignees

Labels

SmallSmaller change solvable in a Pull Requestc: numbersComponent: numbers, currency, unitss: help wantedStatus: help wanted; needs proposal champion

Type

No type

Projects

Status

Previously Discussed

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions