How to get the currency symbol for a given currency string (GBP, USD etc)? The best I've come up with seems ridiculously long winded, is there another way or am I better off with a lookup table?
const userLocale = EN-gb;
const userCurrency = GBP;
const withValueEl = document.querySelector(.withValue);
const withoutValueEl = document.querySelector(.withoutValue);
const valueWithCurrency = Number(0).toLocaleString(userLocale, {
style: currency,
currency: userCurrency,
minimumFractionDigits: 2
});
const valueWithoutCurrency = valueWithCurrency.replace(Number(0).toLocaleString(userLocale, {
minimumFractionDigits: 2
}), )
withValueEl.innerHTML = valueWithCurrency
withoutValueEl.innerHTML = valueWithoutCurrency
With value:<span class=withValue></span><br /> Without value:<span class=withoutValue></span><br />