java向上取整向下取整

来源:互联网 发布:手机页面设计软件 编辑:程序博客网 时间:2024/04/29 12:26

向上取整用Math.ceil(double a)

向下取整用Math.floor(double a)
举例:

public static void main(String[] args) throws Exception {        double a = 35;        double b = 20;        double c = a / b;        System.out.println("c===>" + c); // 1.75        System.out.println("c===>" + Math.ceil(c)); // 2.0        System.out.println(Math.floor(c)); // 1.0    }
0 0