Math.floor,Math.ceil,Math.rint,Math.round用法详解
来源:互联网 发布:艾欧尼亚钻石水平 知乎 编辑:程序博客网 时间:2024/05/17 22:40
本文来源于:http://swiftlet.NET/archives/1369
floor原意:地板。Math.floor函数是求一个浮点数的地板,就是求一个最接近它的整数,它的值小于或等于这个浮点数。看下面的例子:
结果为:
Math.floor(-1.1): -2.0
Math.floor(-1.5): -2.0
Math.floor(-1.6): -2.0
Math.floor(0.1): 0.0
Math.floor(0.5): 0.0
Math.floor(0.6): 0.0
Math.floor(1.1): 1.0
Math.floor(1.5): 1.0
Math.floor(1.6): 1.0
Math.ceil函数讲解
ceil愿意:天花板。Math.ceil函数执行的是向上取整计算,它返回的是大于或等于函数参数,并且与之最接近的整数。看下面的例子:
结果为:
Math.ceil(-1.1): -1.0
Math.ceil(-1.5): -1.0
Math.ceil(-1.6): -1.0
Math.ceil(0.1): 1.0
Math.ceil(0.5): 1.0
Math.ceil(0.6): 1.0
Math.ceil(1.1): 2.0
Math.ceil(1.5): 2.0
Math.ceil(1.6): 2.0
Math.rint函数讲解
Math.rint函数返回最接近参数的整数,如果有2个数同样接近,则返回偶数的那个。
结果为:
Math.rint(-1.1): -1.0
Math.rint(-1.5): -2.0
Math.rint(-1.6): -2.0
Math.rint(0.1): 0.0
Math.rint(0.5): 0.0
Math.rint(0.6): 1.0
Math.rint(1.1): 1.0
Math.rint(1.5): 2.0
Math.rint(1.6): 2.0
Math.round函数讲解
round方法,它表示"四舍五入",算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整
结果为:
Math.round(-1.1): -1
Math.round(-1.5): -1
Math.round(-1.6): -2
Math.round(0.1): 0
Math.round(0.5): 1
Math.round(0.6): 1
Math.round(1.1): 1
Math.round(1.5): 2
Math.round(1.6): 2
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- java Math.floor,Math.ceil,Math.rint,Math.round用法详解
- Math.ceil、Math.floor、Math.round用法
- java Math floor ceil rint round
- Java Math的floor、ceil、rint及round用法
- Math.ceil()和Math.floor()、Math.round()
- Math.round|Math.floor|Math.ceil区别
- Math.floor,Math.round,Math.ceil
- Math.round, Math.ceil 和 Math.floor
- Math.floor()/Math.ceil()/Math.round()
- JavaScript中的Math.ceil()、Math.floor()、Math.round()详解
- Math.round ceil floor
- math.floor、math.ceil
- JS:Math.random(),Math.ceil(),Math.floor()与Math.round()
- 台大林轩田机器学习课程笔记2----机器学习的分类
- Oracle 函数体系
- JAVA中问答4
- iOS敏感词过滤,DFA算法的OC实现
- Oracle 11gR2 create database manually
- Math.floor,Math.ceil,Math.rint,Math.round用法详解
- 堆优化Dijkstra 模版
- Java面试总结
- 第30周-鸟哥的Linux私房菜基础篇第三版-第七章、Linux 档案与目录管理
- JAVA WEB面试题
- Java4android学习笔记5-6
- Uva-727 Equation(中缀表达式转后缀表达式)
- Configure unixODBC connect to Oracle 11g
- Logistic回归