Package java.math
Enum RoundingMode
- All Implemented Interfaces:
Serializable,Comparable<RoundingMode>
public enum RoundingMode extends Enum<RoundingMode>
Specifies the rounding behavior for operations whose results cannot be
represented exactly.
-
Enum Constant Summary
Enum Constants Enum Constant Description CEILINGRounding mode to round towards positive infinity.DOWNRounding mode where the values are rounded towards zero.FLOORRounding mode to round towards negative infinity.HALF_DOWNRounding mode where values are rounded towards the nearest neighbor.HALF_EVENRounding mode where values are rounded towards the nearest neighbor.HALF_UPRounding mode where values are rounded towards the nearest neighbor.UNNECESSARYRounding mode where the rounding operations throws an ArithmeticException for the case that rounding is necessary, i.e.UPRounding mode where positive values are rounded towards positive infinity and negative values towards negative infinity. -
Method Summary
Modifier and Type Method Description static RoundingModevalueOf(int mode)Converts rounding mode constants from classBigDecimalintoRoundingModevalues.static RoundingModevalueOf(String name)Returns the enum constant of this type with the specified name.static RoundingMode[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
UP
Rounding mode where positive values are rounded towards positive infinity and negative values towards negative infinity.
Rule:x.round().abs() >= x.abs() -
DOWN
Rounding mode where the values are rounded towards zero.
Rule:x.round().abs() <= x.abs() -
CEILING
-
FLOOR
-
HALF_UP
Rounding mode where values are rounded towards the nearest neighbor. Ties are broken by rounding up. -
HALF_DOWN
Rounding mode where values are rounded towards the nearest neighbor. Ties are broken by rounding down. -
HALF_EVEN
Rounding mode where values are rounded towards the nearest neighbor. Ties are broken by rounding to the even neighbor. -
UNNECESSARY
Rounding mode where the rounding operations throws an ArithmeticException for the case that rounding is necessary, i.e. for the case that the value cannot be represented exactly.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
valueOf
Converts rounding mode constants from classBigDecimalintoRoundingModevalues.- Parameters:
mode- rounding mode constant as defined in classBigDecimal- Returns:
- corresponding rounding mode object
-