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

enter image description here

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); 

https://jsfiddle.net/v51s34st/


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -