Wednesday, 13 July 2016

jquery - Javascript floating issue with addition

I have following value which give wrong total.



let a = 86.2500;
let b = 32.3550;
alert(a+b); //return 118.60499999999999 , expected 118.605
alert((a+b).toFixed(2)) //return 118.60 , expected 118.61


When I calculate above value with my calculator it give my expected result but javascript give me unexpected result. Why and what is solution to get expected result?




https://jsfiddle.net/vnu9fyb8/1/

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...