//向上取整:Math.ceil() //只要有小数都+1
int a = new Double(Math.ceil(1.23456)).intValue();
System.out.println("向上取整=" + a); //2
//向下取整:Math.floor() //不取小数
int b = new Double(Math.floor(1.23456)).intValue();
System.out.println("向下取整=" + b); //1
//四舍五入:Math.round() //四舍五入
int c = Math.round(1.23456F);
System.out.println("四舍五入=" + c); //1
Java基础 -- 数据取整
最新推荐文章于 2023-03-24 14:20:59 发布