0

I am performing a basic calculation using javascript and when I use this combination of number it won't calculate correctly:

alert((40071.13 + 6028.91) - 46100.04);

It should calculate to 0 but it doesn't. All other number combinations work for me.

Help!

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143

1 Answers1

0

This is a rounding issue. Try this to round to 2 decimal places

var num = (40071.13 + 6028.91) - 46100.04;
alert(num.toFixed(2));

See it in action on jsFiddle

Bijan
  • 7,737
  • 18
  • 89
  • 149