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.floor(11.46)=Math.floor(11.68)=Math.floor(11.5)=11
Math.floor(-11.46)=Math.floor(-11.68)=Math.floor(-11.5)=-12
 
  • 相关阅读:
    基于 mysql 异步驱动的非阻塞 Mybatis【待验证】
    Hive SQL优化方式及使用技巧
    使用Guava-RateLimiter限流控制qps
    hive 时间戳函数之unix_timestamp,from_unixtime
    Hive实现自增列的两种方法
    shell 下 urlencode/urldecode 编码/解码的方法
    awk使用shell变量,shell获取awk中的变量值
    shell脚本删除远程过期文件
    linux下多进程同时操作文件
    hive学习----Hive表的创建
  • 原文地址:https://www.cnblogs.com/qhantime/p/11324099.html
  • 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.floor(11.46)=Math.floor(11.68)=Math.floor(11.5)=11
    Math.floor(-11.46)=Math.floor(-11.68)=Math.floor(-11.5)=-12