System.Number.ParseDouble C# (CSharp) Method

ParseDouble() static private method

static private ParseDouble ( String value, NumberStyles options, NumberFormatInfo numfmt ) : Double
value String
options NumberStyles
numfmt NumberFormatInfo
return Double
        internal unsafe static Double ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) {
            Byte * numberBufferBytes = stackalloc Byte[NumberBuffer.NumberBufferBytes];
            NumberBuffer number = new NumberBuffer(numberBufferBytes);
            Double d = 0;
            
            StringToNumber(value, options, ref number, numfmt, false);

            if (!NumberBufferToDouble(number.PackForNative(), ref d)) {
                throw new OverflowException(Environment.GetResourceString("Overflow_Double"));
            }

            return d;
        }

Usage Example

示例#1
0
        // Parses a double from a String in the given style.  If
        // a NumberFormatInfo isn't specified, the current culture's
        // NumberFormatInfo is assumed.
        //
        // This method will not throw an OverflowException, but will return
        // PositiveInfinity or NegativeInfinity for a number that is too
        // large or too small.
        //
        /// <include file='doc\Double.uex' path='docs/doc[@for="Double.Parse3"]/*' />
        public static double Parse(String s, NumberStyles style, IFormatProvider provider)
        {
            NumberFormatInfo info = NumberFormatInfo.GetInstance(provider);

            try {
                return(Number.ParseDouble(s, style, info));
            } catch (FormatException) {
                //If we caught a FormatException, it may be from one of our special strings.
                //Check the three with which we're concerned and rethrow if it's not one of
                //those strings.
                String sTrim = s.Trim();
                if (sTrim.Equals(info.PositiveInfinitySymbol))
                {
                    return(PositiveInfinity);
                }
                if (sTrim.Equals(info.NegativeInfinitySymbol))
                {
                    return(NegativeInfinity);
                }
                if (sTrim.Equals(info.NaNSymbol))
                {
                    return(NaN);
                }
                //Rethrow the previous exception;
                throw;
            }
        }
All Usage Examples Of System.Number::ParseDouble