JS数据四舍五入 处理小数 , toFixed()的潜在问题

toFixed() 函数使用 问题
toFixed() 函数不能很精确的四舍五入
例如
2.055.toFixed(2) 2.05
2.056.toFixed(2) 2.06
toFixed() 原生的方法 不能够很精确的 四舍五入 这个方法 可以自己编写方式使用
也可以
使用 Math.round(2.055 * 1000 / 10) / 100
Math.round() 方法 是针对 整数的四舍五入 可以 Math.round(2.555 * 1000 / 10) / 100

猜你喜欢

转载自blog.csdn.net/HEshenghuxi/article/details/86149422