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

351
Views
Remove trailing zeros Intl.NumberFormat - JavaScript

What is the best way to remove the trailing zeros from the output when using Javascript NumberFormat to display Swedish currency?

I want output 200 kr instead 200,00 kr

Is there a built-in solution with Intl.NumberFormat to achieve this?

console.log(Intl.NumberFormat('sv-SE', {style:'currency', currency: 'SEK'}).format(200));

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use maximumSignificantDigits maximumFractionDigits. Something like:

function getAmount(number) {
  if ((number | 0) < number) {
    return Intl.NumberFormat('sv-SE', {
      style: 'currency',
      currency: 'SEK'
    }).format(number)
  }
  return Intl.NumberFormat('sv-SE', {
    style: 'currency',
    currency: 'SEK',
    maximumFractionDigits: 0
  }).format(number);
}

console.log(getAmount(200));
console.log(getAmount(200.23));

about 4 years ago · Juan Pablo Isaza Report

0

There is no build-in solution drop only zero fraction, but you can .replace(/\.0+$/,''); - it will not works for currency format, sorry.

To remove any fraction you can use maximumFractionDigits option of Intl.NumberFormat() constructor.

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!