Package org.openl.rules.util
Class Round
- java.lang.Object
-
- org.openl.rules.util.Round
-
public final class Round extends Object
A set of rounding util methods. Note: For OpenL rules only! Don't use it in Java code.- Author:
- Yury Molchan
-
-
Field Summary
Fields Modifier and Type Field Description static RoundingModeCEILINGstatic RoundingModeDOWNstatic RoundingModeFLOORstatic RoundingModeHALF_DOWNstatic RoundingModeHALF_EVENstatic RoundingModeHALF_UPstatic RoundingModeUNNECESSARYstatic RoundingModeUP
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intround(double value)Returns the closestlongto the argument, with ties rounding up.static doubleround(double value, int scale)Round the given value to the specified number of decimal places.static doubleround(double x, int scale, RoundingMode rounding)Round the given value to the specified number of decimal places.static intround(double x, RoundingMode rounding)static intround(float value)Returns the closestintto the argument, with ties rounding up.static floatround(float value, int scale)Round the given value to the specified number of decimal places.static floatround(float x, int scale, RoundingMode rounding)Round the given value to the specified number of decimal places.static intround(float x, RoundingMode rounding)static Integerround(Double value)Likeround(double)but null-safe.static Doubleround(Double value, int scale)Likeround(double, int)but null-safe.static Doubleround(Double x, int scale, int rounding)For backward compatibilitystatic Doubleround(Double value, int scale, RoundingMode rounding)Likeround(double, int, RoundingMode)but null-safe.static Integerround(Double value, RoundingMode roundingMode)static Integerround(Float value)Likeround(float)but null-safe.static Floatround(Float value, int scale)Likeround(float, int)but null-safe.static Floatround(Float x, int scale, int rounding)For backward compatibilitystatic Floatround(Float value, int scale, RoundingMode rounding)Likeround(float, int, RoundingMode)but null-safe.static Integerround(Float value, RoundingMode roundingMode)static BigIntegerround(BigDecimal value)Returns the closest integer to the argument, with ties rounding up.static BigDecimalround(BigDecimal value, int scale)Round the given value to the specified number of decimal places.static BigDecimalround(BigDecimal x, int scale, int rounding)For backward compatibilitystatic BigDecimalround(BigDecimal x, int scale, RoundingMode rounding)Round the given value to the specified number of decimal places.static BigIntegerround(BigDecimal x, RoundingMode rounding)static LongroundStrict(Double value)Likeround(double)but without a ulp amendmentstatic DoubleroundStrict(Double value, int scale)Likeround(double)but without a ulp amendment
-
-
-
Field Detail
-
UP
public static final RoundingMode UP
-
DOWN
public static final RoundingMode DOWN
-
CEILING
public static final RoundingMode CEILING
-
FLOOR
public static final RoundingMode FLOOR
-
HALF_UP
public static final RoundingMode HALF_UP
-
HALF_DOWN
public static final RoundingMode HALF_DOWN
-
HALF_EVEN
public static final RoundingMode HALF_EVEN
-
UNNECESSARY
public static final RoundingMode UNNECESSARY
-
-
Method Detail
-
round
public static Integer round(Double value)
Likeround(double)but null-safe.
-
round
public static Integer round(Double value, RoundingMode roundingMode)
-
round
public static int round(double value)
Returns the closestlongto the argument, with ties rounding up. The value is rounded like using theRoundingMode.HALF_UPmethod. 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
Long.MIN_VALUE, the result is equal to the value ofLong.MIN_VALUE. - If the argument is positive infinity or any value greater than or equal to the value of
Long.MAX_VALUE, the result is equal to the value ofLong.MAX_VALUE.
- Parameters:
value- a floating-point value to be rounded to along.- Returns:
- the value of the argument rounded to the nearest
longvalue.
-
round
public static int round(double x, RoundingMode rounding)
-
round
public static Integer round(Float value)
Likeround(float)but null-safe.
-
round
public static Integer round(Float value, RoundingMode roundingMode)
-
round
public static int round(float value)
Returns the closestintto the argument, with ties rounding up. The value is rounded like using theRoundingMode.HALF_UPmethod. 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
Integer.MIN_VALUE, the result is equal to the value ofInteger.MIN_VALUE. - If the argument is positive infinity or any value greater than or equal to the value of
Integer.MAX_VALUE, the result is equal to the value ofInteger.MAX_VALUE.
- Parameters:
value- a floating-point value to be rounded to an integer.- Returns:
- the value of the argument rounded to the nearest
intvalue.
-
round
public static int round(float x, RoundingMode rounding)
-
round
public static BigInteger round(BigDecimal value)
Returns the closest integer to the argument, with ties rounding up. The value is rounded like using theRoundingMode.HALF_UPmethod.
-
round
public static Double round(Double value, int scale)
Likeround(double, int)but null-safe.
-
round
public static double round(double value, int scale)Round the given value to the specified number of decimal places. The value is rounded using theRoundingMode.HALF_UPmethod.- Parameters:
value- the value to round.scale- the number of digits to the right of the decimal point.- Returns:
- the rounded value.
-
round
public static BigDecimal round(BigDecimal value, int scale)
Round the given value to the specified number of decimal places. The value is rounded using theRoundingMode.HALF_UPmethod.- Parameters:
value- the value to round.scale- the number of digits to the right of the decimal point.- Returns:
- the rounded value.
-
round
public static Float round(Float value, int scale)
Likeround(float, int)but null-safe.
-
round
public static float round(float value, int scale)Round the given value to the specified number of decimal places. The value is rounded using theRoundingMode.HALF_UPmethod.- Parameters:
value- the value to round.scale- the number of digits to the right of the decimal point.- Returns:
- the rounded value.
-
round
public static Double round(Double value, int scale, RoundingMode rounding)
Likeround(double, int, RoundingMode)but null-safe.
-
round
public static double round(double x, int scale, RoundingMode rounding)Round the given value to the specified number of decimal places. The value is rounded using the given method which is any method defined inRoundingMode.- Parameters:
x- the value to round.scale- the number of digits to the right of the decimal point.rounding- the rounding method as defined inRoundingMode.- Returns:
- the rounded value.
-
round
public static Float round(Float value, int scale, RoundingMode rounding)
Likeround(float, int, RoundingMode)but null-safe.
-
round
public static float round(float x, int scale, RoundingMode rounding)Round the given value to the specified number of decimal places. The value is rounded using the given method which is any method defined inRoundingMode.- Parameters:
x- the value to round.scale- the number of digits to the right of the decimal point.rounding- the rounding method as defined inRoundingMode.- Returns:
- the rounded value.
-
round
public static BigDecimal round(BigDecimal x, int scale, RoundingMode rounding)
Round the given value to the specified number of decimal places. The value is rounded using the given method which is any method defined inRoundingMode.- Parameters:
x- the value to round.scale- the number of digits to the right of the decimal point.rounding- the rounding method as defined inRoundingMode.- Returns:
- the rounded value.
-
round
public static BigInteger round(BigDecimal x, RoundingMode rounding)
-
round
public static BigDecimal round(BigDecimal x, int scale, int rounding)
For backward compatibility
-
roundStrict
public static Long roundStrict(Double value)
Likeround(double)but without a ulp amendment
-
-