Inheritance: java.lang.Enum
示例#1
0
 public static RoundingMode valueOf(string name)
 {
     foreach (RoundingMode enumInstance in RoundingMode.values())
     {
         if (enumInstance.nameValue == name)
         {
             return(enumInstance);
         }
     }
     throw new System.ArgumentException(name);
 }
示例#2
0
        /// <summary>
        /// Constructs a new {@code MathContext} with a specified
        /// precision and rounding mode.
        /// </summary>
        /// <param name="setPrecision"> The non-negative {@code int} precision setting. </param>
        /// <param name="setRoundingMode"> The rounding mode to use. </param>
        /// <exception cref="IllegalArgumentException"> if the {@code setPrecision} parameter is less
        ///         than zero. </exception>
        /// <exception cref="NullPointerException"> if the rounding mode argument is {@code null} </exception>
        public MathContext(int setPrecision, RoundingMode setRoundingMode)
        {
            if (setPrecision < MIN_DIGITS)
            {
                throw new IllegalArgumentException("Digits < 0");
            }
            if (setRoundingMode == null)
            {
                throw new NullPointerException("null RoundingMode");
            }

            Precision_Renamed    = setPrecision;
            RoundingMode_Renamed = setRoundingMode;
            return;
        }
示例#3
0
        /// <summary>
        /// Constructs a new {@code MathContext} from a string.
        ///
        /// The string must be in the same format as that produced by the
        /// <seealso cref="#toString"/> method.
        ///
        /// <para>An {@code IllegalArgumentException} is thrown if the precision
        /// section of the string is out of range ({@code < 0}) or the string is
        /// not in the format created by the <seealso cref="#toString"/> method.
        ///
        /// </para>
        /// </summary>
        /// <param name="val"> The string to be parsed </param>
        /// <exception cref="IllegalArgumentException"> if the precision section is out of range
        /// or of incorrect format </exception>
        /// <exception cref="NullPointerException"> if the argument is {@code null} </exception>
        public MathContext(String val)
        {
            bool bad = false;
            int  setPrecision;

            if (val == null)
            {
                throw new NullPointerException("null String");
            }
            try             // any error here is a string format problem
            {
                if (!val.StartsWith("precision="))
                {
                    throw new RuntimeException();
                }
                int fence = val.IndexOf(' '); // could be -1
                int off   = 10;               // where value starts
                setPrecision = Convert.ToInt32(val.Substring(10, fence - 10));

                if (!val.StartsWith("roundingMode=", fence + 1))
                {
                    throw new RuntimeException();
                }
                off = fence + 1 + 13;
                String str = val.Substring(off, val.Length() - off);
                RoundingMode_Renamed = RoundingMode.ValueOf(str);
            }
            catch (RuntimeException)
            {
                throw new IllegalArgumentException("bad string format");
            }

            if (setPrecision < MIN_DIGITS)
            {
                throw new IllegalArgumentException("Digits < 0");
            }
            // the other parameters cannot be invalid if we got here
            Precision_Renamed = setPrecision;
        }