记录前端js计算修复方法:
修复前:
console.log (1-0.9);
修复后
var result = 1-0.9;
if (result != null && result != '' && !isNaN(result)) {
var c = result.toString();
if (/\.\d*999999/.test(c) || /\.\d*0000000/.test(c)) {
var _m = Math.pow(10, 6);
result = Math.round(parseFloat(result)*_m)/_m;//result.toFixed(6);
}
}
console.log (result);
评论区