JAVA中double转int类型按四舍五入取整(实用)

public static void main(String[] args) {
        System.out.println("向上取整:" + (int) Math.ceil(96.1));// 97 (去掉小数凑整:不管小数是多少,都进一)
        System.out.println("向下取整" + (int) Math.floor(96.8));// 96 (去掉小数凑整:不论小数是多少,都不进位)
        System.out.println("四舍五入取整:" + Math.round(96.1));// 96 (这个好理解,不解释)
        System.out.println("四舍五入取整:" + Math.round(96.8));// 97
    }

在这里插入图片描述

posted @ 2022-11-21 18:54  TwcatL_tree  阅读(299)  评论(0编辑  收藏  举报