js运算丢精度问题解决方法
解决方法:使用toFixed(2) 四舍五入
来处理
有问题的计算
console.log((4565.15100)) // 456514.99999999994
console.log((4565.15100).toFixed(2)) // 456515.00
console.log((4565.19100)) // 456518.99999999994
console.log((4565.19100).toFixed(2)) // 456519.00
console.log((0.1 + 0.2)) // 0.30000000000000004
console.log((0.1 + 0.2).toFixed(2)) // 0.30
console.log(0.11+0.10, (0.11+0.10).toFixed(2), ‘------1’);
console.log(0.11+0.12, (0.11+0.12).toFixed(2), ‘------2’);
console.log(0.12+0.17, (0.12+0.17).toFixed(2), ‘------3’);
console.log(0.13+0.16, (0.13+0.16).toFixed(2), ‘------4’);
console.log(0.13+0.17, (0.13+0.17).toFixed(2), ‘------5’);
console.log(0.14+0.15, (0.14+0.15).toFixed(2), ‘------6’);
console.log(0.14+0.16, (0.14+0.16).toFixed(2), ‘------7’);
console.log(0.14+0.17, (0.14+0.17).toFixed(2), ‘------8’);
console.log(0.14+0.18, (0.14+0.18).toFixed(2), ‘------9’);
console.log(0.15+0.17, (0.15+0.17).toFixed(2), ‘------10’);
console.log(0.15+0.18, (0.15+0.18).toFixed(2), ‘------11’);
console.log(0.15+0.19, (0.15+0.19).toFixed(2), ‘------12’);
console.log(0.16+0.18, (0.16+0.18).toFixed(2), ‘------13’);