0

Hi I am doing following operation in Javascript and I am getting weird results, can someone tell me what is going on.

5.62-6.18+0.56 = 4.440892098500626e-16
  • This is normal, and not weird. Same thing will happen in C# etc,. Some decimal number just cannot be expressed exactly using IEEE format. – Keith Apr 11 '18 at 20:50

1 Answers1

0

Because of floating point inaccuracies, the result isn't exactly zero. JavaScript uses scientific notation to display numbers as small as this one. You might be interested in the toPrecision() method.

Maya
  • 1,490
  • 12
  • 24