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
Written by Avner Cohen
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#