二、toFixed可以四舍五入吗?
答案是可以。但是问题也正在于此。这种四舍五入是不稳定的(不同的浏览器不一样)。
(1).
在ie7下点击按钮会显示0.00,而ff会是0.01。
(2)
ie和ff都正常。
解决方法
< html >
< head >
< script type ="text/javascript" >
Number.prototype.toFixed = function (s)
{
return (parseInt( this * Math.pow( 10 , s ) + 0.5 ) / Math.pow( 10 , s )).toString();
}
</ script >
</ head >
< body >
< input onclick ="alert(0.009.toFixed(2))" type ="button" value ="显示0.009.toFixed(2)" >
</ body >
</ html >