閱讀418 返回首頁    go 微軟 go Office


javascript 取整

    <script language="javascript">
        var t = 3.1415;
        alert("int(" + t + ") = " + int(t));
        /******** 內置取整函數 *********/
        alert("parseInt(" + t + ") = " + parseInt(t));
        /******** floor是地板的意思,顧名思義是向下取整 *********/
        alert("Math.floor(" + t + ") = " + Math.floor(t));
        /******** 四舍五入函數 *********/
        alert("Math.round(" + t + ") = " + Math.round(t));
        /******** ceil 是天花板的意思,顧名思義是向上取整 *********/
        alert("Math.ceil(" + t + ") = " + Math.ceil(t));
        /******** 自定義取整函數,原理是扣除餘數 *********/
        function int(num) { return num - num % 1 }
    </script>

最後更新:2017-04-03 20:19:53

  上一篇:go 下個十年PC與服務器的發展變化
  下一篇:go Java中類成員初始化順序問題