js 解决减法运算丢失精度的问题

94 阅读1分钟
function toFixed22(value, precision = 2) {
    const factor = Math.pow(10, precision);
    return Math.round(value * factor) / factor;
}
let a = 33.3 - 29.3;
let res = toFixed22(a)

console.log(res)