On-line Guides

How To Guides






The JavaScript FAQ
Prev Home Next

Accuracy

Question: Sometimes JavaScript computations seem to yield "inaccurate" results, e.g. 0.362*100=36.199999999999996. How can I avoid this?

Answer: To avoid "inaccurate" results, you might want to round the results to the precision of the data you used. For example, in order to round the result to one thousandth, you can use this code:

roundedX = Math.round(1000*rawX)/1000;

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


Mirrored with kind permission of Alexei Kourbatov Design by Interspire

AltStyle によって変換されたページ (->オリジナル) /