1.1:Java中取整有哪三种方式???什么是取整除法???什么是浮点除法???

学习:第7遍

常见单词:
——》【ceil】


1.Java中取整有哪三种方式???

方式一:向上取整Math.ceil();
如:Math.ceil(1.1)=2;
Math.ceil(1.5)=2;
Math.ceil(1.9)=2;

方式二:向下取整Math.floor();
如:Math.floor(1.1)=1;
Math.floor(1.5)=-1;
Math.floor(1.9)=-1;

方式三:四舍五入Math.round();
四舍五入后取整,其算法为Math.floor(x+0.5)
即原来的数字加上0.5之后向下取整
如:Math.round(1.1)=1;
Math.round(1.5)=2;
Math.round(1.9)=2;


2.什么是取整除法???什么是浮点除法???

如果相除的两个数都是整数,那么结果也是整数
这叫做取整除法。
比如,3/2,结果是1。

整数之间的除法,默认只返回整数位
也就相当于Math.floor()向下取整

如果其中有一个是浮点数,那么就是浮点除法
结果是浮点数
比如,3.0/2,结果是1.5