Class 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
    • Method Detail

      • round

        public static int round​(double value)
        Returns the closest long to the argument, with ties rounding up. The value is rounded like using the RoundingMode.HALF_UP method.

        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 of Long.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 of Long.MAX_VALUE.
        Parameters:
        value - a floating-point value to be rounded to a long.
        Returns:
        the value of the argument rounded to the nearest long value.
      • round

        public static int round​(double x,
                                RoundingMode rounding)
      • round

        public static int round​(float value)
        Returns the closest int to the argument, with ties rounding up. The value is rounded like using the RoundingMode.HALF_UP method.

        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 of Integer.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 of Integer.MAX_VALUE.
        Parameters:
        value - a floating-point value to be rounded to an integer.
        Returns:
        the value of the argument rounded to the nearest int value.
      • round

        public static int round​(float x,
                                RoundingMode rounding)
      • 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 the RoundingMode.HALF_UP method.
        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 the RoundingMode.HALF_UP method.
        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)
        Round the given value to the specified number of decimal places. The value is rounded using the RoundingMode.HALF_UP method.
        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 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 in RoundingMode.
        Parameters:
        x - the value to round.
        scale - the number of digits to the right of the decimal point.
        rounding - the rounding method as defined in RoundingMode.
        Returns:
        the rounded value.
      • 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 in RoundingMode.
        Parameters:
        x - the value to round.
        scale - the number of digits to the right of the decimal point.
        rounding - the rounding method as defined in RoundingMode.
        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 in RoundingMode.
        Parameters:
        x - the value to round.
        scale - the number of digits to the right of the decimal point.
        rounding - the rounding method as defined in RoundingMode.
        Returns:
        the rounded value.
      • round

        public static Double round​(Double x,
                                   int scale,
                                   int rounding)
        For backward compatibility
      • round

        public static Float round​(Float x,
                                  int scale,
                                  int rounding)
        For backward compatibility
      • round

        public static BigDecimal round​(BigDecimal x,
                                       int scale,
                                       int rounding)
        For backward compatibility
      • roundStrict

        public static Long roundStrict​(Double value)
        Like round(double) but without a ulp amendment
      • roundStrict

        public static Double roundStrict​(Double value,
                                         int scale)
        Like round(double) but without a ulp amendment