return (int)floor(a + 0.5f);
}
public static long round(double a) {
return (long)floor(a + 0.5d);
}
/**
* Returns the <code>double</code> value that is closest in value
* to the argument and is equal to a mathematical integer. If two
* <code>double</code> values that are mathematical integers are
* equally close, the result is the integer value that is
* even. Special cases:
* <ul><li>If the argument value is already equal to a mathematical
* integer, then the result is the same as the argument.
* <li>If the argument is NaN or an infinity or positive zero or negative
* zero, then the result is the same as the argument.</ul>
*
* @param a a <code>double</code> value.
* @return the closest floating-point value to <code>a</code> that is
* equal to a mathematical integer.
*/
public static double rint(double a) {
return StrictMath.rint(a); // default impl. delegates to StrictMath
}
public static double rint(double a) {
return StrictMath.rint(a); // default impl. delegates to StrictMath
}
ceil方法和floor方法的运算是相反的
/**
* Returns the smallest (closest to negative infinity)
* <code>double</code> value that is greater than or equal to the
* argument and is equal to a mathematical integer. Special cases:
* <ul><li>If the argument value is already equal to a
* mathematical integer, then the result is the same as the
* argument. <li>If the argument is NaN or an infinity or
* positive zero or negative zero, then the result is the same as
* the argument. <li>If the argument value is less than zero but
* greater than -1.0, then the result is negative zero.</ul> Note
* that the value of <code>Math.ceil(x)</code> is exactly the
* value of <code>-Math.floor(-x)</code>.
*
*
* @param a a value.
* @return the smallest (closest to negative infinity)
* floating-point value that is greater than or equal to
* the argument and is equal to a mathematical integer.
*/
public static double ceil(double a) {
return StrictMath.ceil(a); // default impl. delegates to StrictMath
}
/**
* Returns the largest (closest to positive infinity)
* <code>double</code> value that is less than or equal to the
* argument and is equal to a mathematical integer. Special cases:
* <ul><li>If the argument value is already equal to a
* mathematical integer, then the result is the same as the
* argument. <li>If the argument is NaN or an infinity or
* positive zero or negative zero, then the result is the same as
* the argument.</ul>
*
* @param a a value.
* @return the largest (closest to positive infinity)
* floating-point value that less than or equal to the argument
* and is equal to a mathematical integer.
*/
public static double floor(double a) {
return StrictMath.floor(a); // default impl. delegates to StrictMath
}
System.out.println(Math.ceil(-1.0890)); ======== -1.0
System.out.println(Math.ceil(1.0890)); ======== 2.0
System.out.println(Math.floor(-1.0890)); ======== -2.0
System.out.println(Math.floor(1.0890)); ======== 1.0
System.out.println(Math.rint(-1.0890)); ======== -1.0
System.out.println(Math.rint(1.0890)); ======== 1.0
System.out.println(Math.round(-1.0890)); ======== -1
System.out.println(Math.round(1.0890)); ========= 1