/**
* Math.floor : 向下取整,即返回不大于当前数的最大整数
* Math.round : 四舍五入
* Math.ceil : 向上取整,即返回大于当前数的最小整数
*
* @author ZHOUMI2
*
*/
public class Test {
public static void main(String[] args) {
double[] numArr = { -1.5, 1.5 };
for (double num : numArr) {
System.out.print("floor(" + num + ") = " + Math.floor(num));
System.out.print(" | round(" + num + ") = " + Math.round(num));
System.out.print(" | ceil(" + num + ") = " + Math.ceil(num) + "\n");
}
}
}
// 运行结果
floor(-1.5) = -2.0 | round(-1.5) = -1 | ceil(-1.5) = -1.0
floor(1.5) = 1.0 | round(1.5) = 2 | ceil(1.5) = 2.0
Math.floor,Math.round,Math.ceil
最新推荐文章于 2024-12-26 16:46:25 发布