TryParseDouble() static private method

static private TryParseDouble ( String value, NumberStyles options, NumberFormatInfo numfmt, Double &result ) : Boolean
value String
options NumberStyles
numfmt NumberFormatInfo
result Double
return Boolean
Exemplo n.º 1
0
        private static bool TryParse(String s, NumberStyles style, NumberFormatInfo info, out double result)
        {
            if (s == null)
            {
                result = 0;
                return(false);
            }
            bool success = Number.TryParseDouble(s, style, info, out result);

            if (!success)
            {
                String sTrim = s.Trim();
                if (sTrim.Equals(info.PositiveInfinitySymbol))
                {
                    result = PositiveInfinity;
                }
                else if (sTrim.Equals(info.NegativeInfinitySymbol))
                {
                    result = NegativeInfinity;
                }
                else if (sTrim.Equals(info.NaNSymbol))
                {
                    result = NaN;
                }
                else
                {
                    return(false); // We really failed
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out double result)
        {
            bool success = Number.TryParseDouble(s, style, info, out result);

            if (!success)
            {
                ReadOnlySpan <char> sTrim = s.Trim();
                if (sTrim.EqualsOrdinal(info.PositiveInfinitySymbol))
                {
                    result = PositiveInfinity;
                }
                else if (sTrim.EqualsOrdinal(info.NegativeInfinitySymbol))
                {
                    result = NegativeInfinity;
                }
                else if (sTrim.EqualsOrdinal(info.NaNSymbol))
                {
                    result = NaN;
                }
                else
                {
                    return(false); // We really failed
                }
            }
            return(true);
        }
Exemplo n.º 3
0
 private static bool TryParse(string s, NumberStyles style, NumberFormatInfo info, out double result)
 {
     if (s == null)
     {
         result = 0.0;
         return(false);
     }
     if (!Number.TryParseDouble(s, style, info, out result))
     {
         string str = s.Trim();
         if (str.Equals(info.PositiveInfinitySymbol))
         {
             result = double.PositiveInfinity;
         }
         else if (str.Equals(info.NegativeInfinitySymbol))
         {
             result = double.NegativeInfinity;
         }
         else
         {
             if (!str.Equals(info.NaNSymbol))
             {
                 return(false);
             }
             result = double.NaN;
         }
     }
     return(true);
 }
Exemplo n.º 4
0
 private static bool TryParse(ReadOnlySpan <char> s, NumberStyles style, NumberFormatInfo info, out double result)
 {
     return(Number.TryParseDouble(s, style, info, out result));
 }