Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
Intl.NumberFormat Get the Currency Code from a Dynamic Locale?

I am struggling to find a good way to get the Currency Code for Intl.NumberFormat from my locale.

We have the ability for the user to change locale at any time. I need a way to retrieve the currency code based on the selected locale so that I can format appropriately.

let chosenLocale = appSettings.LocaleKey; //Could be anything user chooses en-US, ja-JP, etc..

// THIS DOES NOT EXIST, DOES ANY SUCH MAPPING, LOOKUP, OR LIST EXIST?
let currencyBasedOnLocale = GetCurrencyCodeFromLocale(chosenLocale); 

// WOULD BE COOL IF THERE WAS THIS FOR ALL KNOWN CURRENCIES:
// var localeCurrencyLookup = { "en-US": "USD", "ru-RU" : "RUB", "en-GB" : "GBP", etc... }
// THEN I COULD DO THIS:
// let currencyBasedOnLocale = localeCurrencyLookup[chosenLocale] || "USD"; 

var formatter = new Intl.NumberFormat(chosenLocale, {
    style: 'currency',
    currency: currencyBasedOnLocale
});
return formatter.format(value);

So does anyone know if such a mapping of locales to currency codes exist? Or is there some other way I can find the currency code based on the locale? I feel like this is a huge oversite to not have a locale to currency mapping. Perhaps most sites only support a few locales, leaving the developer to hash it out manually. I do not mind typing out a json lookup mapping object, but I do not even know where to go to see which locales map to which currency code.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda