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 -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -

How to understand 2 main() functions after using uftrace to profile the C++ program? -