parseInt()可将字符串转化成整数

解决方案 »

  1.   

    floor 方法
    请参阅
    ceil 方法 | Math 对象方法应用于: Math 对象
    要求
    版本 1
    返回小于等于其数值参数的最大整数。Math.floor(number)
    必选项 number 参数是数值表达式。说明
    返回值为小于等于其数值参数的最大整数值。==========================================
    var xxxx=12.34;
    alert( Math.floor(xxxx+0.5) );
      

  2.   

    Math.round(number)它就是四舍五入的方法
      

  3.   

    function myRound(num,n){
        var newNum = num;
        newNum = Math.pow(10,n);
        newNum = Math.round(newNum);
        for (i=0;i<n;i++) newNum /= 10;
        return newNum
    } JS提供的这些函数parseInt floor round只是各种样式的取整,不是真正数学意义上的四舍五入。
      

  4.   

    <script>
    alert((2.57).toFixed(1))
    </script>
      

  5.   

    for (i=0;i<n;i++) newNum /= 10;
    可以改成 newNum = Math.pow(0.1,n);
      

  6.   

    function Round(a_Num , a_Bit) 
      { 
       return( Math.round(a_Num * Math.pow (10 , a_Bit)) / Math.pow(10 , a_Bit)) ; 
    }
      

  7.   

    toFixed()要ie5.5+支持,所以,如果是98就会报错,
    刚写了个实现toFixed()功能的函数.
    为了版本兼容,我们得自己写函数实现.<script>
    // by wanghr100
    /* 这样,就可以直接用toFixed()了.*/
    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((52.277).toFixed(2))
    alert((100.024).toFixed(1))
    </script>
      

  8.   

    抱歉!网络问题,一直没有上来!我用的是FormatNumber().楼上的几位有时间试一试!