Class RoundingUtil


  • @Scriptable
    public final class RoundingUtil
    extends Object
    • Method Detail

      • roundHalfAwayFromZero

        public static double roundHalfAwayFromZero​(double p_dbl)
        Round half away from zero (in German: Kaufmännisches Runden, DIN 1333).

        Returns the closest integer to the argument. Negative half values are rounded to the lower value.

        Examples:

         roundHalfAwayFromZero(0)    ->  0.0
         roundHalfAwayFromZero(0.5)  ->  1.0
         roundHalfAwayFromZero(-0.5) -> -1.0
         roundHalfAwayFromZero(1)    ->  1.0
         roundHalfAwayFromZero(-1)   -> -1.0
         

        Parameters:
        p_dbl - The value to be rounded.
        Returns:
        The rounded value. If the given value is NaN, or not finite, no rounding is performed and the given value is returned.
      • roundHalfAwayFromZero

        public static double roundHalfAwayFromZero​(double p_dbl,
                                                   int p_iPrecision)
        Round half away from zero (in German: Kaufmännisches Runden, DIN 1333).

        Returns the closest integer to the argument. Negative half values are rounded to the lower value.

        Examples:

         roundHalfAwayFromZero(0.0, 2)     ->    0.0
         roundHalfAwayFromZero(1.0, 2)     ->    1.0
         roundHalfAwayFromZero(-1.0, 2)    ->   -1.0
         roundHalfAwayFromZero(1.255, 2)   ->    1.26
         roundHalfAwayFromZero(-1.255, 2)  ->   -1.26
         roundHalfAwayFromZero(123.5, -2)  ->  100.0
         roundHalfAwayFromZero(-123.5, -2) -> -100.0
         

        Parameters:
        p_dbl - The value to be rounded.
        p_iPrecision - The precision (may be a negative value).
        Returns:
        The rounded value. If the given value is NaN, or not finite, no rounding is performed and the given value is returned.
      • roundHalfAwayFromZero

        public static BigDecimal roundHalfAwayFromZero​(BigDecimal p_bd)
        Round half away from zero (in German: Kaufmännisches Runden, DIN 1333).

        Returns the closest integer to the argument. Negative half values are rounded to the lower value.

        Examples:

         roundHalfAwayFromZero(0)    ->  0.0
         roundHalfAwayFromZero(0.5)  ->  1.0
         roundHalfAwayFromZero(-0.5) -> -1.0
         roundHalfAwayFromZero(1)    ->  1.0
         roundHalfAwayFromZero(-1)   -> -1.0
         

        Parameters:
        p_bd - The value to be rounded.
        Returns:
        The rounded value.
      • roundHalfAwayFromZero

        public static BigDecimal roundHalfAwayFromZero​(BigDecimal p_bd,
                                                       int p_iPrecision)
        Round half away from zero (in German: Kaufmännisches Runden, DIN 1333).

        Returns the closest integer to the argument. Negative half values are rounded to the lower value.

        Examples:

         roundHalfAwayFromZero(0.0, 2)     ->    0.0
         roundHalfAwayFromZero(1.0, 2)     ->    1.0
         roundHalfAwayFromZero(-1.0, 2)    ->   -1.0
         roundHalfAwayFromZero(1.255, 2)   ->    1.26
         roundHalfAwayFromZero(-1.255, 2)  ->   -1.26
         roundHalfAwayFromZero(123.5, -2)  ->  100.0
         roundHalfAwayFromZero(-123.5, -2) -> -100.0
         

        Parameters:
        p_bd - The value to be rounded.
        p_iPrecision - The precision (may be a negative value).
        Returns:
        The rounded value.
      • roundHalfEven

        public static double roundHalfEven​(double p_dbl)
        Returns the closest integer to the argument. Half values are rounded to the neares even integer.

        Examples:

         roundHalfEven(0)     ->  0.0
         roundHalfEven(1)     ->  1.0
         roundHalfEven(-1)    -> -1.0
         roundHalfEven(0.5)   ->  0.0
         roundHalfEven(-0.5)  ->  0.0
         roundHalfEven(1.5)   ->  2.0
         roundHalfEven(-1.5)  -> -2.0
         roundHalfEven(0.12)  ->  0.0
         roundHalfEven(-0.12) ->  0.0
         roundHalfEven(0.62)  ->  1.0
         roundHalfEven(-0.62) -> -1.0
         

        Parameters:
        p_dbl - The value to be rounded.
        Returns:
        The rounded value. If the given value is NaN, or not finite, no rounding is performed and the given value is returned.
      • roundHalfEven

        public static double roundHalfEven​(double p_dbl,
                                           int p_iPrecision)
        Returns the closest scaled integer to the argument. Half values are rounded to the neares even scaled integer.

        Examples:

         roundHalfEven(0, 2)       ->    0.0
         roundHalfEven(1, 2)       ->    1.0
         roundHalfEven(-1, 2)      ->   -1.0
         roundHalfEven(1.245, 2)   ->    1.24
         roundHalfEven(1.255, 2)   ->    1.26
         roundHalfEven(125.5, -2)  ->  100.0
         roundHalfEven(150, -2)    ->  200.0
         

        Parameters:
        p_dbl - The value to be rounded.
        p_iPrecision - The precision (may be a negative value).
        Returns:
        The rounded value. If the given value is NaN, or not finite, no rounding is performed and the given value is returned.
      • roundHalfEven

        public static BigDecimal roundHalfEven​(BigDecimal p_bd)
        Returns the closest integer to the argument. Half values are rounded to the neares even integer.

        Examples:

         roundHalfEven(0)     ->  0.0
         roundHalfEven(1)     ->  1.0
         roundHalfEven(-1)    -> -1.0
         roundHalfEven(0.5)   ->  0.0
         roundHalfEven(-0.5)  ->  0.0
         roundHalfEven(1.5)   ->  2.0
         roundHalfEven(-1.5)  -> -2.0
         roundHalfEven(0.12)  ->  0.0
         roundHalfEven(-0.12) ->  0.0
         roundHalfEven(0.62)  ->  1.0
         roundHalfEven(-0.62) -> -1.0
         

        Parameters:
        p_bd - The value to be rounded.
        Returns:
        The rounded value.
      • roundHalfEven

        public static BigDecimal roundHalfEven​(BigDecimal p_bd,
                                               int p_iPrecision)
        Returns the closest scaled integer to the argument. Half values are rounded to the neares even scaled integer.

        Examples:

         roundHalfEven(0, 2)       ->    0.0
         roundHalfEven(1, 2)       ->    1.0
         roundHalfEven(-1, 2)      ->   -1.0
         roundHalfEven(1.245, 2)   ->    1.24
         roundHalfEven(1.255, 2)   ->    1.26
         roundHalfEven(125.5, -2)  ->  100.0
         roundHalfEven(150, -2)    ->  200.0
         

        Parameters:
        p_bd - The value to be rounded.
        p_iPrecision - The precision (may be a negative value).
        Returns:
        The rounded value.