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

145
Views
Round number with lots of decimal places in Javascript

I have a number with an extreme amount of decimal places.

1.5583255870000002e+36

I'm struggling to find a good way to round this down to 2 decimal places using JavaScript.

I've tried a few variations using parseFloat() Math.round() and .toFixed().

Here is an example using .toPrecision().

App.currentUSDBalance = Number((App.currentBalance * App.maticPrice).toPrecision(2));

The result is 1.6e+36. I was hoping for something like 1.59.

Thanks,

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

0

The following snippet should be the answer to your updated question:

const yourNumber=1.234567890123e36, ndigits=3;

// returns two variations of the solution:
function mySigDig(num,dig){
 return [+(num/(10**Math.floor(Math.log10(num)))).toPrecision(dig),
 +num.toPrecision(dig).replace(/e.*/,"")]
}


console.log(mySigDig(23,ndigits));
console.log(mySigDig(2345678,ndigits));
console.log(mySigDig(yourNumber,ndigits));

about 4 years ago · Juan Pablo Isaza Report

0

Apologies for the terrible question.

I ended up solving this by converting to string and dropping the e+X.

App.currentUSDBalance = Number((App.currentBalance * App.maticPrice).toPrecision(3)).toString().split('e')[0];

Thanks for the help.

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!