Math.round函数

Returns the closest {@code long} to the argument, with ties
rounding to positive infinity.

返回一个最接近的值,如果是0.5,上下距离一样,向正无穷方向取值,其实就是取较大的值。

   @Test
    public void testRound(){
        System.out.println(Math.round(12.5));  //13
        System.out.println(Math.round(-12.5));   //-12
        System.out.println(Math.round(-12.6));   //-13
    }

你可能感兴趣的:(java)