Division inaccurate in Javascript?

Posted by Nate on Stack Overflow See other posts from Stack Overflow or by Nate
Published on 2012-11-17T16:52:24Z Indexed on 2012/11/17 17:00 UTC
Read the original article Hit count: 216

Filed under:
|

If I perform the following operation in Javascript:

0.06120*400

The result is 24.48.

However, if I do this:

24.48/400

The result is:

0.061200000000000004

JSFiddle: http://jsfiddle.net/zcDH7/

So it appears that Javascript rounds things differently when doing division and multiplication?

Using my calculator, the operation 24.48/400 results in the correct answer of 0.0612.

How should I deal with Javascript's inaccurate division? I can't simply round the number off, because I will be dealing with numbers of varying precision.

Thanks for your advice.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about division