Thursday, 17 August 2017

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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...