Last Updated: February 25, 2016
·
1.675K
· avnerner

In JS (0.1 + 0.2 != 0.3)

I find many new comers to JS to miss that on float calculations.

if precise calculation is needed, it sometimes usefully to try something like:

var a = 0.1;
var b= 0.2
var FACTOR = 1000;
var c = a * FACTOR ;
var d  = b * FACTOR ;
var sum = (c + d) / FACTOR ;

More details at:
http://javascript.info/tutorial/number-math#imprecise-calculations