Saturday 26 October 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...