java double类型 向上取整,向下取整,四舍五入

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

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

四舍五入取整:Math.round(double a)

直接取整数:intValue()

    public static void main(String[] args) {
        Double number = 5.3;
        Double number1 = 5.8;
        //向上取整
        Double ceil = Math.ceil(number);
        System.out.println("向上取整:" + ceil);
        //向下取整
        Double floor = Math.floor(number);
        System.out.println("向下取整:" + floor);
        //四舍五入
        double round = Math.round(number);
        double round1 = Math.round(number1);
        System.out.println("四舍五入:" + round);
        System.out.println("四舍五入:" + round1);
        //直接取整数
        int intValue = number.intValue();
        System.out.println("直接取整数:" + intValue);
    }

java double类型 向上取整,向下取整,四舍五入_第1张图片

你可能感兴趣的:(知识点总结,JavaSE,java,开发语言)