场景 前端计算金额时,经常会出现浮点型过长的问题,所以需要一个四舍五入的方法来保证小数的位数。 function main () { console.log(0.06 * 40.08) } main() 复制代码 得出结果: 1. 使用toFixed function main () { let res = (1.12 * 40.08) console.log('toFixed前: ' + res + ', 类型: ' + t...
场景 前端计算金额时,经常会出现浮点型过长的问题,所以需要一个四舍五入的方法来保证小数的位数。 function main () { console.log(0.06 * 40.08) } main() 复制代码 得出结果: 1. 使用toFixed function main () { let res = (1.12 * 40.08) console.log('toFixed前: ' + res + ', 类型: ' + t...