zoukankan      html  css  js  c++  java
  • Math.round(),Math.ceil(),Math.floor()取整计算

    1.Math.round():根据“round”的字面意思“附近、周围”,可以猜测该函数是求一个附近的整数,看下面几个例子就明白。

    小数点后第一位<5
    正数:Math.round(11.46)=11
    负数:Math.round(-11.46)=-11
     
    小数点后第一位>5
    正数:Math.round(11.68)=12
    负数:Math.round(-11.68)=-12
     
    小数点后第一位=5
    正数:Math.round(11.5)=12
    负数:Math.round(-11.5)=-11
    ===================>总结:(小数点后第一位)大于五全部加,等于五正数加,小于五全不加。
     

    2.Math.ceil():根据“ceil”的字面意思“天花板”去理解;

    例如:
    Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=12
    Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-11
     

    3.Math.floor():根据“floor”的字面意思“地板”去理解;

    例如:
    Math.ceil(11.46)=Math.ceil(11.68)=Math.ceil(11.5)=11
    Math.ceil(-11.46)=Math.ceil(-11.68)=Math.ceil(-11.5)=-12
  • 相关阅读:
    禁止页面缓存 移动端
    常见的请求头与响应头介绍
    阮一峰 ES6学习
    禁止页面缩放 移动端
    10月30日学习日志
    11月7日学习日志
    11月6日学习日志
    10月31日学习日志
    11月1日学习日志
    11月9日学习日志
  • 原文地址:https://www.cnblogs.com/henji/p/8678987.html
Copyright © 2011-2022 走看看