6

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"

Gabe O'Leary
  • 2,010
  • 4
  • 24
  • 41
  • 1
    No access to check first but what happens if you specify pl-PL as the first parameter in the examples above? –  Jul 25 '17 at 22:31

2 Answers2

2

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);
NicoleMoore
  • 325
  • 2
  • 14
  • 2
    So this means we have to change the number formatting in order to use the symbol. If we want to display multiple "obscure" currencies with symbols, the formatting would not be consistent... `[['pl', 'PLN'], ['th', 'THB']].map(([locale, currency]) => new Intl.NumberFormat(locale, { style: 'currency', currency, currencyDisplay: 'symbol' }).format(10000))` yields `["10 000,00 zł", "฿10,000.00"]` – DLight Aug 07 '20 at 17:16
  • This is nonsense. Isn't there a way to override this behavior? – Lajos Mészáros Jun 25 '23 at 10:49
1

According to the spec:

However, the set of combinations of currency code and language tag for which localized currency symbols are available is implementation dependent. Where a localized currency symbol is not available, the ISO 4217 currency code is used for formatting.

  • 3
    What does "not available" mean...? Is there anywhere I can contribute the currency symbols for these ISO codes so I can continue using this formatter or will I have to come up with an alternate solution? – Gabe O'Leary May 12 '16 at 22:10
  • I might suggest available are [symbols that are present in unicode](http://www.fileformat.info/info/unicode/category/Sc/list.htm). – Роман Парадеев May 13 '16 at 08:28