1.round(a)
a+0.5,然后向下取整。如果a是float类型,返回int;如果a是double类型,返回long。
- Math.round(-5.6) = - 6
- Math.round(-5.4) = - 5
- Math.round(-5.5) = - 5
- Math.round(5.6) = 6
- Math.round(5.5) = 6
- Math.round(5.4) = 5
2.ceil(b)
向上取整,b为double,返回double
- Math.ceil(-5.5) = - 5.0
- Math.ceil(-5.4) = - 5.0
- Math.ceil(-5.6) = - 5.0
- Math.ceil(5.5) = 6.0
- Math.ceil(5.6) = 6.0
- Math.ceil(5.4) = 6.0
3.floor(x)
向下取整,x为double,返回double
- Math.ceil(-5.5) = - 6.0
- Math.ceil(-5.4) = - 6.0
- Math.ceil(-5.6) = - 6.0
- Math.ceil(5.5) = 5.0
- Math.ceil(5.6) = 5.0
- Math.ceil(5.4) = 5.0
4.如有错误,望大佬不吝赐教!感激~