扫码关注官方订阅号
var n = 0.015.toFixed(2); console.log(n);
真实结果"0.01",但是想得到"0.02",求解决方法
toFixed存在兼容性问题,0.015.toFixed(2)各浏览器结果:
toFixed
0.015.toFixed(2)
Chorme: 0.01 FF: 0.01 IE7,8,9:0.02
可以这样写:Math.round(0.015*100)/100,抽取成公用的方法
Math.round(0.015*100)/100
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
toFixed
存在兼容性问题,0.015.toFixed(2)
各浏览器结果:可以这样写:
Math.round(0.015*100)/100
,抽取成公用的方法