Java中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
来源:互联网 发布:扁平化与金字塔 知乎 编辑:程序博客网 时间:2024/04/30 16:10
转载来源:http://blog.csdn.net/isee361820238/article/details/52369890
1、Math.floor()
先看定义:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
由定义可知:Math.floor()表示向下取整。,即小于或等于double型参数的整数位的数字。
比如:Math.floor(18.7)的结果是18.0,Math.floor(-18.3)的结果-19.0,下面再列出几组:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
2、Math.round()
接下来看Math.round()的定义:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
由定义可以很清楚的知道:Math.round()方法表示的是“四舍五入”的计算。
算法为Math.floor(f+0.5),即将原来的数字加上0.5后再向下取整
Math.round(18.5)的结果为19,Math.round(-18.5)的结果为-18。下面再列出几组:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
3、Math.ceil()
Math.ceil的定义为:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
由定义也可知:Math.ceil()方法就表示向上取整。即大于或等于double型参数的整数位的数字。
比如:Math.ceil(18.3)的结果是19.0,Math.ceil(-18.7)的结果-18.0。再看看一组:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
4、Math.rint()
Math.rint()的定义:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
Math.ring()返回double值最接近参数的值,并等于某个整数。如果两个double值跟整数都同样接近,结果是整数值是偶数。特殊情况:
如果参数值已经等于某个整数,那么结果跟参数一样。
如果参数为NaN或无穷大,正零或负零,那么结果和参数一样。
比如例子:
阅读全文
0 0
- Java中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
- Android中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
- java 中 Math.round() Math.ceil() Math.floor()区别
- java中Math.round(),Math.ceil(),Math.floor()运算
- Math ceil(),floor(),round()方法的使用
- Java Math的floor、ceil、round方法
- Java Math的floor、ceil、rint及round方法
- java中Math方法的ceil,floor,round方法
- Java Math类的三个方法ceil,floor,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()
- Math.ceil、Math.floor、Math.round用法
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- Math ceil()、floor()、round()方法
- pthread_create()之前的属性设置
- 学习认识HTML基础入门Day01
- 编程思想之多线程与多进程(4)——C++中的多线程
- [luogu-1563]noip2016day1-T1 玩具谜题 题解
- php可变变量的用法
- Java中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用
- H5定位指针矫正
- Java基础9:ArrayList和Array使用
- PHP注册页面生成验证码的实现
- JSONObject解析Boolean类型出现异常
- 线程,进程,协程
- html与js加载顺序
- bootStap支treeViewjs
- LeetCode 643. Maximum Average Subarray I