阅读418 返回首页    go 阿里云 go 技术社区[云栖]


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中类成员初始化顺序问题