Get currency from country code
shubham0804 opened this issue · 1 comments
shubham0804 commented
I looked at the docs and tried the library and wanted to know if I can get the default currency symbol and the default separator and delimiter that is used in a particular country by passing the two digit country code to currency.js?
I believe custom currency symbols, separators and delimiters can be set but I wanted a way to do that without having to code for 100 different currencies.
scurker commented
This library primarily handles parse/formatting of currencies, so it doesn't have any built-in locale lookups.
Assuming you knew the currency you wanted to lookup, you could kinda pass those values into currency.js
:
var parts = new Intl.NumberFormat(navigator.language, { style: 'currency', currency: 'USD' }).formatToParts(10000);
var symbol= parts.find(p => p.type === 'currency').value;
var separator = parts.find(p => p.type === 'group').value;
var decimal = parts.find(p => p.type === 'decimal').value;
Other than using Intl
, there's not a direct way to get the default symbol, separator, or decimal.