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

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -