java 中的 Math.round(-1.5) 等于多少?

1 个回答

  • java小生
    见过花就好,何必在意花属于谁。
    Math.round(-1.5)的返回值是-1。四舍五入的原理是在参数上加0.5然后做向下取整。 我们可以通过大量实验看下结果: ```java public class test { public static void main(String[] args){ System.out.println(Math.round(1.3)); //1 System.out.println(Math.round(1.4)); //1 System.out.println(Math.round(1.5)); //2 System.out.println(Math.round(1.6)); //2 System.out.println(Math.round(1.7)); //2 System.out.println(Math.round(-1.3)); //-1 System.out.println(Math.round(-1.4)); //-1 System.out.println(Math.round(-1.5)); //-1 System.out.println(Math.round(-1.6)); //-2 System.out.println(Math.round(-1.7)); //-2 } } ```
    发布于 2021-06-29 17:14 •IP属地 安徽
    举报
    评论
    收藏