zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    Single Number II
    Best Time to Buy and Sell Stock
    Linked List Cycle
    Single Number
    Max Points on a Line
    Strategy
    LRU Cache
    Word Break II
    Text Justification
    Median of Two Sorted Arrays
  • 原文地址:https://www.cnblogs.com/zhangqs008/p/3059784.html
Copyright © 2011-2022 走看看