Enum ERounding

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ERounding>

    public enum ERounding
    extends java.lang.Enum<ERounding>
    Specifies the mode to use when "shortening" numbers that otherwise can't fit a given number of digits, so that the shortened number has about the same value. This "shortening" is known as rounding. (The "E" stands for "extended", and has this prefix to group it with the other classes common to this library, particularly EDecimal, EFloat, and ERational.).
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      Ceiling
      If there is a fractional part, the number is rounded to the highest representable number that's closest to it.
      Down
      The fractional part is discarded (the number is truncated).
      Floor
      If there is a fractional part, the number is rounded to the lowest representable number that's closest to it.
      HalfDown
      Rounded to the nearest number; if the fractional part is exactly half, it is discarded.
      HalfEven
      Rounded to the nearest number; if the fractional part is exactly half, the number is rounded to the closest representable number that is even.
      HalfUp
      Rounded to the nearest number; if the fractional part is exactly half, the number is rounded to the closest representable number away from zero.
      None
      Indicates that rounding will not be used.
      Odd
      Deprecated.
      Consider using ERounding.OddOrZeroFiveUp instead.
      OddOrZeroFiveUp
      For binary floating point numbers, this is the same as Odd.
      Up
      If there is a fractional part, the number is rounded to the closest representable number away from zero.
      ZeroFiveUp
      Deprecated.
      Use ERounding.OddOrZeroFiveUp instead.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ERounding valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static ERounding[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • None

        public static final ERounding None
        Indicates that rounding will not be used. If rounding is required, the rounding operation will report an error.
      • Up

        public static final ERounding Up
        If there is a fractional part, the number is rounded to the closest representable number away from zero.
      • Down

        public static final ERounding Down
        The fractional part is discarded (the number is truncated).
      • HalfUp

        public static final ERounding HalfUp
        Rounded to the nearest number; if the fractional part is exactly half, the number is rounded to the closest representable number away from zero. This is the most familiar rounding mode for many people.
      • HalfDown

        public static final ERounding HalfDown
        Rounded to the nearest number; if the fractional part is exactly half, it is discarded.
      • HalfEven

        public static final ERounding HalfEven
        Rounded to the nearest number; if the fractional part is exactly half, the number is rounded to the closest representable number that is even. This is sometimes also known as "banker's rounding".
      • Ceiling

        public static final ERounding Ceiling
        If there is a fractional part, the number is rounded to the highest representable number that's closest to it.
      • Floor

        public static final ERounding Floor
        If there is a fractional part, the number is rounded to the lowest representable number that's closest to it.
      • Odd

        @Deprecated
        public static final ERounding Odd
        Deprecated.
        Consider using ERounding.OddOrZeroFiveUp instead.
        If there is a fractional part and the whole number part is even, the number is rounded to the closest representable odd number away from zero.
      • ZeroFiveUp

        @Deprecated
        public static final ERounding ZeroFiveUp
        Deprecated.
        Use ERounding.OddOrZeroFiveUp instead.
        If there is a fractional part and if the last digit before rounding is 0 or half the radix, the number is rounded to the closest representable number away from zero; otherwise the fractional part is discarded. In overflow, the fractional part is always discarded.
      • OddOrZeroFiveUp

        public static final ERounding OddOrZeroFiveUp
        For binary floating point numbers, this is the same as Odd. For other bases (including decimal numbers), this is the same as ZeroFiveUp. This rounding mode is useful for rounding intermediate results at a slightly higher precision (at least 2 bits more for binary) than the final precision.
    • Method Detail

      • values

        public static ERounding[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (ERounding c : ERounding.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static ERounding valueOf​(java.lang.String name)
        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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null