老问题了,四舍五入了/*
===========================================
//保留小数点位数
===========================================
*/
Number.prototype.toFixed=function(len)
{
if(isNaN(len)||len==null)
{
len = 0;
}
else
{
if(len<0)
{
len = 0;
}
} return Math.round(this * Math.pow(10,len)) / Math.pow(10,len);}alert(0.999999.toFixed(2));
===========================================
//保留小数点位数
===========================================
*/
Number.prototype.toFixed=function(len)
{
if(isNaN(len)||len==null)
{
len = 0;
}
else
{
if(len<0)
{
len = 0;
}
} return Math.round(this * Math.pow(10,len)) / Math.pow(10,len);}alert(0.999999.toFixed(2));
Math.round(yourValue*100)/100;保留两位小数.
<!--
Number.prototype.toFixed = function(len)
{
//IE5.0不支持toFiexed,我们可以自己写函数实现.
return Math.round(this * Math.pow(10,len))/Math.pow(10,len)
}
var a = 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1;
alert(a);
alert((a).toFixed(1));
//-->
</SCRIPT>