ParseSingle() static private méthode

static private ParseSingle ( String value, NumberStyles options, NumberFormatInfo numfmt ) : Single
value String
options NumberStyles
numfmt NumberFormatInfo
Résultat Single
Exemple #1
0
 // Parses a float 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 path='docs/doc[@for="Single.Parse3"]/*' />
 public static float Parse(String s, NumberStyles style)
 {
     try {
         return(Number.ParseSingle(s, style));
     }
     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(NumberFormatInfo.positiveInfinitySymbol))
         {
             return(PositiveInfinity);
         }
         if (sTrim.Equals(NumberFormatInfo.negativeInfinitySymbol))
         {
             return(NegativeInfinity);
         }
         if (sTrim.Equals(NumberFormatInfo.nanSymbol))
         {
             return(NaN);
         }
         //Rethrow the previous exception;
         throw;
     }
 }
Exemple #2
0
 public static float Parse(String s, IFormatProvider provider)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseSingle(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #3
0
 // Parses a float 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.
 //
 public static float Parse(String s)
 {
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseSingle(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo));
 }
Exemple #4
0
 public static float Parse(String s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #5
0
 public static float Parse(string s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     if (s == null)
     {
         ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     }
     return(Number.ParseSingle(s, style, NumberFormatInfo.CurrentInfo));
 }
Exemple #6
0
 private static float Parse(string s, NumberStyles style, NumberFormatInfo info)
 {
     try
     {
         return(Number.ParseSingle(s, style, info));
     }
     catch (FormatException)
     {
         string str = s.Trim();
         if (str.Equals(info.PositiveInfinitySymbol))
         {
             return(PositiveInfinity);
         }
         if (str.Equals(info.NegativeInfinitySymbol))
         {
             return(NegativeInfinity);
         }
         if (!str.Equals(info.NaNSymbol))
         {
             throw;
         }
         return(NaN);
     }
 }
Exemple #7
0
 private static float Parse(String s, NumberStyles style, NumberFormatInfo info)
 {
     return(Number.ParseSingle(s, style, info));
 }
Exemple #8
0
 public static float Parse(ReadOnlySpan <char> s, NumberStyles style = NumberStyles.Float | NumberStyles.AllowThousands, IFormatProvider provider = null)
 {
     NumberFormatInfo.ValidateParseStyleFloatingPoint(style);
     return(Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #9
0
 public static float Parse(string s, NumberStyles style, IFormatProvider provider)
 {
     NumberFormatInfo2.ValidateParseStyleFloatingPoint(style);
     return(Number.ParseSingle(s, style, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #10
0
 public static float Parse(string s, NumberStyles style)
 {
     NumberFormatInfo2.ValidateParseStyleFloatingPoint(style);
     return(Number.ParseSingle(s, style, NumberFormatInfo.CurrentInfo));
 }
Exemple #11
0
 public static float Parse(string s, IFormatProvider provider)
 {
     return(Number.ParseSingle(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.GetInstance(provider)));
 }
Exemple #12
0
 public static float Parse(string s)
 {
     return(Number.ParseSingle(s, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo));
 }