The answers of similar questions are not adequate. So before marking this as a duplicate of similar questions such as for example Proper currency format when not displaying the native currency of a culture, please consider the entire question.
I wish to properly format any currency according to the formatting specifications of any locale. This means that
- The currency does not have to match the locale's currency.
- The locale does not have to use ISO codes for formatting.
In other words, I do not wish to apply locale-aware formatting of digits only, while re-using the currency symbol from another locale, because
- Currency symbols for a currency may differ between different locales
- Different locales may use the same currency symbol for different currencies
Let's consider two locales, en-US and en-AU, and two currencies, USD and AUD. I would expect localized output for "100 USD is 131 AUD" to be en-US: $100.00 is A$131.00 en-AU: USD100.00 is $131.00
In javascript this is easily achieved using Intl.NumberFormat
let aud = {style: 'currency', currency: 'AUD'};
let usd = {style: 'currency', currency: 'USD'};
let usFormatAUD = new Intl.NumberFormat('en-US', aud);
let usFormatUSD = new Intl.NumberFormat('en-US', usd);
let auFormatAUD = new Intl.NumberFormat('en-AU', aud);
let auFormatUSD = new Intl.NumberFormat('en-AU', usd);
Then
`${usFormatUSD.format(100)} is ${usFormatAUD.format(131)}`
will give "$100.00 is A$131.00"
`${auFormatUSD.format(100)} is ${auFormatAUD.format(131)}`
will give "USD100.00 is $131.00"
Copying NumberFormatInfo.CurrencySymbol from one locale to the other as suggested in answers to similar questions would result in "$100.00 is $131.00", which does not retain the meaning of the actual currencies.
Using currency codes as suggested in answers to similar questions would result in "USD100.00 is AUD131.00" which is incorrectly formatted currencies in both locales.