美文网首页
【Java面试题】59 Math.round(11.5)等于多少

【Java面试题】59 Math.round(11.5)等于多少

作者: 暖熊熊 | 来源:发表于2017-10-22 16:55 被阅读0次

Math类中提供了三个与取整有关的方法:
ceil、天花板,向上取整
floor、地板,向下取整
round,四舍五入
下面程序结果与上述规则相符:

public class Test{
    public static void main(String[] args) {
        System.out.println(Math.round(11.5));   //12
        System.out.println(Math.round(-11.5));  //-11
        System.out.println(Math.ceil(11.5));    //12
        System.out.println(Math.ceil(-11.5));   //-11
        System.out.println(Math.floor(11.5));   //-11
        System.out.println(Math.floor(-11.5));  //-12
    }
}

相关文章

网友评论

      本文标题:【Java面试题】59 Math.round(11.5)等于多少

      本文链接:https://www.haomeiwen.com/subject/zixnuxtx.html