Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser intl.NumberFormat not displaying currency symbols correctly

I'm attempting to write a currency formatting function using Intl.NumberFormat. It works correctly when I pass it things like USD, or EUR as the currency, but seems to break when I pass it more obscure currency codes like PLN or COL, and instead of displaying their symbols as requested it displays the Codes. It is clearly recognizing the code because when I ask it to display the name instead it works correctly:

Intl.NumberFormat("en-US",{
  style:'currency',
  minimumIntegerDigits:1,
  currency: 'PLN',
  currencyDisplay: 'symbol'
}).format(43);

Displays "PLN43" while

Intl.NumberFormat("en-US",{
  style:'currency',
  minimumIntegerDigits:1,
  currency: 'PLN',
  currencyDisplay: 'name'
}).format(43);

Displays "43.00 Polish zlotys"

like image 310
Gabe O'Leary Avatar asked May 12 '16 18:05

Gabe O'Leary


Video Answer


1 Answers

The Intl.NumberFormat should have the symbols you need, you just have to make sure you specify the correct language code.

You can find a mapping of ISO language codes here: https://www.w3schools.com/tags/ref_language_codes.asp

In this case you will need to use the Polish value "pl" instead of "en-US"

Intl.NumberFormat("pl",{
  style:'currency',
  minimumIntegerDigits:1,
  currency: 'PLN',
  currencyDisplay: 'symbol'
}).format(43);
like image 154
NicoleMoore Avatar answered Sep 29 '22 22:09

NicoleMoore