<script>
var x=123.45;
alert(x.toFixed(0));
alert(x.toFixed(1));
</script>

解决方案 »

  1.   

    <script>
    function test(){
    alert(Math.floor(document.all.t1.value)) ;
    alert(Math.ceil(document.all.t1.value)) ;
    }
    </script>
    <BODY BGCOLOR="#FFFFFF">
    <input type=text name=t1>
    <input type="button" onclick="test();" value="test">
    </BODY>
      

  2.   

    好像不能四舍五入,试试这个:function getInt(lng){
      num=parseInt(lng);
      if(lng-num>0.5)
        num++;
      return num;
    }var s = 231.534;
    alert(getInt(s));