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

176
Visualizações
Set Currency code at the end in Intl.NumberFormat()

I am using Intl.NumberFormat() to format different currency correctly. Sadly, I have a requirement that want me to put all code at the end of the value, and not at the start.

So something like this is fine, but the code is at the start and not at the end/

const number = 123456.789;


// the Japanese yen doesn't use a minor unit
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency',currencyDisplay:'code', currency: 'JPY' }).format(number));
// expected output: JPY 123,457"
// I want  123,457 JPY

Is there a way to force it at the end without having to manually add it at the end by doing .replace('JYP','').trim()

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I think you'll have to handle it manually. The Intl library formats the position of the code / symbol based on the given locale. Given the code is always 3 uppercase alpha characters, it should be easy to detect it.

const formatCurrency = (amount, locale, currency) => {
  const fmt = new Intl.NumberFormat(locale, {
    style: "currency",
    currencyDisplay: "code",
    currency   
  });
  return fmt.format(amount).replace(/^([A-Z]{3})\s*(.+)$/, "$2 $1");
};

const number = 123456.789;

([
  { locale: "ja-JP", currency: "JPY" },
  { locale: "en-US", currency: "USD" },
  { locale: "fr-FR", currency: "EUR" }, // already right-aligned
]).forEach(({ locale, currency }) => {
  console.log(formatCurrency(number, locale, currency));
});

about 4 years ago · Juan Pablo Isaza Relatório
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