<script>
Number.prototype.toFixed=function(len)
{
    var add = 0;
    var s,temp;
    var s1 = this + "";
    var start = s1.indexOf(".");
    if(s1.substr(start+len+1,1)>=5)add=1;
    var temp = Math.pow(10,len);
    s = Math.floor(this * temp) + add;
    return s/temp;
}
alert((0.06).toFixed(1))
</script>

解决方案 »

  1.   

    http://blog.csdn.net/wanghr100/archive/2004/04/05/16365.aspx
      

  2.   

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    /*
    ===========================================
    //保留小数点位数
    ===========================================
    */
    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(new Number('1.06').toFixed(1));
    alert(new Number('0.06').toFixed(1));
    //-->
    </SCRIPT>
      

  3.   

    重新定义也好的,不过想不通toFixed设计的初衷...还有以上诸位做的不好,alert(new Number('1.06').toFixed(4)); 你们输出的都是1.06而不是1.0600