java中的向上取整和向下取整

向上取整:比自己大的最小整数。
向下取整:比自己小的最大整数。

public class RoundingUp {
    public static void main(String[] args) {
        System.out.println(Math.ceil(1.5)); //2.0
        System.out.println(Math.ceil(-1.5)); //-1.0
        System.out.println(Math.floor(1.5)); //1.0
        System.out.println(Math.floor(-1.5)); //-2.0
    }
}
发布了102 篇原创文章 · 获赞 101 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43124279/article/details/104855860