5

Here is a sample program:

var a = parseFloat("86.69043189999999") + "<br>";
var b = parseFloat("86.79718199999999") + "<br>";
var n = a + b;
document.getElementById("demo").innerHTML = n;
<p id=demo></p>

Both the two variables have exact same decimal point still it's giving two different kind of output:

86.6904319
86.79718199999999

Why such an weird behaviour?

SeinopSys
  • 8,787
  • 10
  • 62
  • 110
Anurag Chakraborty
  • 421
  • 2
  • 5
  • 20
  • I can't give a complete answer, but I have a feeling the root of the problem may stem from the fact that floats are inherently weird: http://stackoverflow.com/questions/1458633/how-to-deal-with-floating-point-number-precision-in-javascript – Josh Beam Aug 12 '15 at 06:24

0 Answers0