Saturday, October 26, 2019

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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...