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

214
Views
How to format a number in js with maximum 6 number after comma

i have to do a task that make a number separates every thousands with commas and maximum 6 number after 'dot' in js. For examples

12345678.1234567 -> 12,345,678.123457 (need to round)
12345678.1234533 -> 12,345,678.123453
12345678.12      -> 12,345,678.12
12345678.0       -> 12,345,678

I tried with some localeString and toFixed

Number(number.toFixed(6)).toLocaleString("en-US");

but always face some exceptions and i do not how to round after dot also. What should i do?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try Intl.NumberFormat()

const numbers = [12345678.0, 12345678.12, 12345678.123456, 12345678.1234567];
const f = new Intl.NumberFormat('en-US', { maximumFractionDigits: 6 });

numbers.forEach(n => console.log(f.format(n)));

about 4 years ago · Santiago Trujillo Report

0

You can use maximumFractionDigits

var number = 12345678.1234567;
const formatted = number.toLocaleString("en", {   
   minimumFractionDigits: 0,
   maximumFractionDigits: 6,
});
console.log(formatted);

about 4 years ago · Santiago Trujillo 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!