Math取整方法
2016-04-11 16:40
323 查看
舍掉小数取整:Math.floor(2)=2
舍掉小数取整:Math.floor(2.1)=2
舍掉小数取整:Math.floor(-2.1)=-3
舍掉小数取整:Math.floor(-2.5)=-3
舍掉小数取整:Math.floor(-2.9)=-3
四舍五入取整:Math.rint(2)=2
四舍五入取整:Math.rint(2.1)=2
四舍五入取整:Math.rint(-2.5)=-2
四舍五入取整:Math.rint(2.5)=2
四舍五入取整:Math.rint(2.9)=3
四舍五入取整:Math.rint(-2.9)=-3
四舍五入取整:Math.rint(-2.49)=-2
四舍五入取整:Math.rint(-2.51)=-3
凑整:Math.ceil(2)=2
凑整:Math.ceil(2.1)=3
凑整:Math.ceil(2.5)=3
凑整:Math.ceil(2.9)=3
舍掉小数取整:Math.floor(-2)=-2
舍掉小数取整:Math.floor(-2.1)=-3
舍掉小数取整:Math.floor(-2.5)=-3
舍掉小数取整:Math.floor(-2.9)=-3
凑整:Math.ceil(-2)=-2
凑整:Math.ceil(-2.1)=-2
凑整:Math.ceil(-2.5)=-2
凑整:Math.ceil(-2.9)=-2
Math.round(3.14)3
Math.round(3.5)4
Math.round(-3.14)-3
Math.round(-3.5)-3
总结:floor向下取整,ceil向上取整;round和rint四舍五入,取绝对值后舍入,然后加上符号,遇到.5的时候向绝对值小的方向舍之。
舍掉小数取整:Math.floor(2.1)=2
舍掉小数取整:Math.floor(-2.1)=-3
舍掉小数取整:Math.floor(-2.5)=-3
舍掉小数取整:Math.floor(-2.9)=-3
四舍五入取整:Math.rint(2)=2
四舍五入取整:Math.rint(2.1)=2
四舍五入取整:Math.rint(-2.5)=-2
四舍五入取整:Math.rint(2.5)=2
四舍五入取整:Math.rint(2.9)=3
四舍五入取整:Math.rint(-2.9)=-3
四舍五入取整:Math.rint(-2.49)=-2
四舍五入取整:Math.rint(-2.51)=-3
凑整:Math.ceil(2)=2
凑整:Math.ceil(2.1)=3
凑整:Math.ceil(2.5)=3
凑整:Math.ceil(2.9)=3
舍掉小数取整:Math.floor(-2)=-2
舍掉小数取整:Math.floor(-2.1)=-3
舍掉小数取整:Math.floor(-2.5)=-3
舍掉小数取整:Math.floor(-2.9)=-3
凑整:Math.ceil(-2)=-2
凑整:Math.ceil(-2.1)=-2
凑整:Math.ceil(-2.5)=-2
凑整:Math.ceil(-2.9)=-2
Math.round(3.14)3
Math.round(3.5)4
Math.round(-3.14)-3
Math.round(-3.5)-3
总结:floor向下取整,ceil向上取整;round和rint四舍五入,取绝对值后舍入,然后加上符号,遇到.5的时候向绝对值小的方向舍之。
相关文章推荐
- 从零创建maven工程
- 过程神经元网络
- maven部署应用到tomcat
- COGS738 [网络流24题] 数字梯形(最小费用最大流)
- 径向渐变
- Hibernate-Native SQL
- ASP.NET跨服务器上传文件的相关解决方案
- JDK源码阅读——ArrayList(2)
- 关闭程序
- Android中的Toast重复显示的问题
- Linux 下系统调用的三种方法
- window.location 与window.open的区别
- 比较两个数据库所有表的字段
- SQLite Page Cache之事务处理(2)
- 开启线程池 加入任务 传入参数 此任务能够在执行完成时得到返回值
- 【转载】 Java线程面试题 Top 50
- Javascript模块化编程(一):模块的写法
- IntelliJ IDEA 12 创建Web项目 教程 超详细版
- 设计模式六大原则(2):里氏替换原则
- AppDomain (转)