首页 > javascript toFixed()的问题

javascript toFixed()的问题

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,抽取成公用的方法

【热门文章】
【热门文章】