<script language=javascript>
<!--
a=1.1+0.6;
a=a.toFixed(1)
alert(a); 
//-->
</script>

解决方案 »

  1.   

    ssm1226(雨中人) : 我的意思是如何进行浮点运算,准确计算 alert(1.1+0.6); //结果是1.7000000000000001  只是举例而已,我不明白为什么会出现这样的结果~谢谢你的回复~ 
    :)
      

  2.   

    IE的问题。
    <script>
    String.prototype.fn = function(n)
      { s=""
        for(i=0;i<n;i++)s+=this
        return s
      }
    Number.prototype.fix = function(num)
      {with(Math)return (round(this.valueOf()*pow(10,num))/pow(10,num)).toString().search(/\./i)==-1?(round(this.valueOf()*pow(10,num))/pow(10,num)).toString()+"."+"0".fn(num):(round(this.valueOf()*pow(10,num))/pow(10,num));
      }
    alert((1.1+0.6).fix(2));
    </script>
    上边的代码返回任意数的保留n位小数值,为了考虑货币的效果(xx.xx)形势,所以长了一点儿,因为4.00的格式是不能显示的(以数字方式),如果不用顾及那个用下边的就行
    <script>
    Number.prototype.fix = function(num)
      {with(Math)return round(this.valueOf()*pow(10,num))/pow(10,num);
      }
    alert((1.1+0.6).fix(2));
    </script>