javascript - Float multiplication in JS produces wrong result -


this question has answer here:

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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -