javascript - Float multiplication in JS produces wrong result -
this question has answer here:
- is floating point math broken? 20 answers
came across weird result in javascript (actually python well)
var = 80.1 var b = 100 var a/b = 0.8009999999999999 var = 80.1 var b = 100 var a*b = 8009.999999999999
same not happen 80.2
would know why happens
the mathematical representation used javascript
in ieee 754
there not numbers can represented ieee 754
. if want perform division , proper result need use rounding of decimal values like,
var = 80.1; var b = 100; console.log((a/b).tofixed(3));
Comments
Post a Comment