Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!