I don't understand how NumberFormat works.
In France we never use $US
so why do I get the following?
new Intl.NumberFormat("fr-FR",{
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
}).format("345")
"345,00 $US"
new Intl.NumberFormat("fr-FR",{
style: 'currency',
currency: 'EUR',
minimumFractionDigits: 2,
}).format("345")
"345,00 €"
Also: the following does not make any sense to me either. I tried random locales to see the impact and get different results for these 2:
new Intl.NumberFormat("en-HOS",{
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
}).format("345")
"345,00 $US"
new Intl.NumberFormat("en-HOSSDDG",{
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2,
}).format("345")
"$345.00"
Is this API broken or I miss something?
You need to use the narrow option when formatting numbers in JS
"narrowSymbol" to use a narrow format symbol ("$100" rather than "US$100"),
const amount = 123444;
console.log(new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', currencyDisplay: 'narrowSymbol'}).format(amount));
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat for full details.
V8 JavaScript engine is using ICU library for i18N.
See there for all currency data: https://github.com/unicode-org/icu/tree/master/icu4c/source/data/curr
But for sure French people use $ and not $US when talking about US dollar.
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