The following works in Chrome:
var formatted = (value * 1).toLocaleString('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 });
but IE/Edge and Firefox throw the error:
RangeError: invalid digits value: 0
The Mozilla docs for toLocaleString:
maximumFractionDigits: The maximum number of fraction digits to use. Possible values are from 0 to 20
A closer read of the docs for NumberFormat shows that, for USD currency, the default value for minimumFractionDigits
is 2. Setting both minimumFractionDigits
and maximumFractionDigits
to 0 fixed the issue. From this is seems that in IE and Edge maximumFractionDigits
must be >= minimumFractionDigits
, when specifying currency (at least)
var formatted = (value * 1).toLocaleString('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0, minimumFractionDigits: 0 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With