var n = 0.015.toFixed(2);
console.log(n);
真实结果"0.01",但是想得到"0.02",求解决方法
toFixed
存在兼容性问题,0.015.toFixed(2)
各浏览器结果:
Chorme: 0.01
FF: 0.01
IE7,8,9:0.02
可以这样写:Math.round(0.015*100)/100
,抽取成公用的方法
var n = 0.015.toFixed(2);
console.log(n);
真实结果"0.01",但是想得到"0.02",求解决方法
toFixed
存在兼容性问题,0.015.toFixed(2)
各浏览器结果:
Chorme: 0.01
FF: 0.01
IE7,8,9:0.02
可以这样写:Math.round(0.015*100)/100
,抽取成公用的方法