Java 中的 Math. round(-1. 5) 等于多少?
答案:-1
/**
* Returns the closest {@code long} to the argument, with ties
* rounding to positive infinity.
*
*
Special cases:
*
- If the argument is NaN, the result is 0.
*
- If the argument is negative infinity or any value less than or
* equal to the value of {@code Long.MIN_VALUE}, the result is
* equal to the value of {@code Long.MIN_VALUE}.
*
- If the argument is positive infinity or any value greater than or
* equal to the value of {@code Long.MAX_VALUE}, the result is
* equal to the value of {@code Long.MAX_VALUE}.
*
* @param a a floating-point value to be rounded to a
* {@code long}.
* @return the value of the argument rounded to the nearest
* {@code long} value.
* @see java.lang.Long#MAX_VALUE
* @see java.lang.Long#MIN_VALUE
*/
看代码的定义就是返回最接近参数的long型整数,如果有两个,就返回大的那个;
通俗点直接+0.5后取整就是要的结果。