先乘以100,取整,再除以100如3.1425926
Math.round(3.1415926*100)/100=3.14

解决方案 »

  1.   

    <script>
    alert(3.1245.toFixed(2))
    </script>
      

  2.   

    toFixed(2)方法要求ie5.5以上版本
    修改一下,判断是否number支持toFixed(),不支持就自己加上:
    <script>
    if(!Number.prototype.toFixed!)
      {Number.prototype.toFixed= function(num)
        {with(Math)return round(this.valueOf()*pow(10,num))/pow(10,num);
        }
      }
    alert(3.1245.toFixed(2))
    </script>
      

  3.   

    啊,修改
    if(!Number.prototype.toFixed!)
    -〉if(!Number.prototype.toFixed)
      

  4.   

    thank you !我也找到了!是toFixed(), 那么如何实现“1,333,222,111.24”这样的格式呢?请高手给于解答!谢谢!