alert(Number.toFixed(9.39393));
返回的是9.39
但是只有ie5.5以上的版本才支持。

解决方案 »

  1.   

    保留两位好像是这样吧
    var a = 9.39393;
    alert(a.toFixed(2));
      

  2.   

    同事的做法: function roundFun(numberRound,roundDigit) //四舍五入,保留位数为roundDigit 
     {
     if (numberRound>=0)
     {
    var tempNumber = parseInt((numberRound * Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);
    return tempNumber;
    }
    else 
     {
    numberRound1=-numberRound
    var tempNumber = parseInt((numberRound1 * Math.pow(10,roundDigit)+0.5))/Math.pow(10,roundDigit);
    return -tempNumber;
    }
         }
      

  3.   

    <script>
    tmp = "1234567.57232"
    result = tmp.substr(0,tmp.indexOf(".")+3);
    alert(result);
    </script>
      

  4.   

    截取保留几位小数点的函数
    <script language=JavaScript>
    function tofloat(f,dec) { 
    if(dec<0) return "Error:dec<0!"; 
    result=parseInt(f)+(dec==0?"":"."); 
    f-=parseInt(f); 
    if(f==0) 
    for(i=0;i<dec;i++) result+='0'; 
    else { 
    for(i=0;i<dec;i++) f*=10; 
    result+=parseInt(Math.round(f)); 

    return result; 

    alert(tofloat(11.20000000000000000001,5))
    </script>