javascript - how to deal with this round off error -
when did simple arithmetic in javascript, there thing kind of round off error. don't want this, don't know how deal it. example:
38.8 * 3 => 116.39999999999999
use this
function multiply (a, b) { exp = b.tostring().length - 2; function makeint (num) { return num * math.pow(10, exp); } function makefloat(num) { return num / math.pow(100, exp); } return makefloat(makeint(a) * makeint(b)); } var result = multiply(38.8,3) console.log(result);
Comments
Post a Comment