smileTan

导航

js reduce 求和误差

const formatNum = function(f, digit) {
var m = Math.pow(10, digit);
return Math.round(f * m,10) / m;
}
 
let sum= arr.reduce((t,c)=>formatNum(t+c.money,10),0);

 

posted on 2020-05-11 19:11  smileTan  阅读(696)  评论(0编辑  收藏  举报