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

216
Views
How to stop Javascript from rounding numbers after 16 decimal places?

Let's say I have the following code:

console.log(1 / 3);

It prints "0.3333333333333333".

Is there a way to not have it stop?

(For any curious souls: it's for calcuating Pi)

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

0

Write a function whrere the numbers are multiplied with precision before they divided:

function div(num1, num2, prec=100) {
  return (num1*prec)/(num2*prec).toFixed(prec)
}

console.log(div(1,3,100));
console.log(div(11,13,100));

about 4 years ago · Juan Pablo Isaza Report

0

Use the .toFixed method:

console.log((1/3).toFixed(2))

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!