While fixing an validation error preventing user from saving with the message
"You have 100%. You need to have 100%!"
I have ran into very interesting issue happening in both Firefox 34 and IE 11:
0.57+8.36+3.36+0.19
gives in Firefox and Chrome
12.479999999999999
And in IE
12.479999999999998
If no one wants to calculate, correct result would be 12.48
I will fix issue now by using Math.Round in reduce function to "correct" value on every step, but real question is, what is cause of this at the first look (of naive user) incorrect behavior?
Note that I have originally discovered issue by trying to sum an Array:
[ 0.57, 8.36, 3.36, 0.19, 39.29, 6.37, 17.24, 0.16, 2.07, 0.04, 22.36].sum()
[ 0.57, 8.36, 3.36, 0.19, 39.29, 6.37, 17.24, 0.16, 2.07, 0.04, 22.36].reduce(function(item,item2){return item+item2})