1

If I use the windows calculator to calculate

(1.75 + 3/1.75)/2 it yields to =

1,7321428571428571428571428571429

If I do the same with javascript it yields to

1.732142857142857206298458550009

So at position 22 after the decimal point the result becomes incorrect ...142857... vs. ...206298...

var a = 1.75;
var res = (a+3/a)/2;
console.log(res.toFixed(30));

How can I make my division precise for 31 digits after the decimal comma?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
knowledge
  • 941
  • 1
  • 11
  • 26

1 Answers1

1

Javascript can't do that "per se", since its double variables have a limited precision. You'll need to use an external library to handle operations with big precision numbers, like this one: Javascript Bignum

Joanvo
  • 5,677
  • 2
  • 25
  • 35