This documentation is archived and is not being maintained.

Double.TryParse Method

Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating point number equivalent.

[Visual Basic]
Public Shared Function TryParse( _
   ByVal s As String, _
   ByVal style As NumberStyles, _
   ByVal provider As IFormatProvider, _
   <Out()> ByRef result As Double _
) As Boolean
public static bool TryParse(
 string s,
 NumberStyles style,
 IFormatProvider provider,
   out double result
public: static bool TryParse(
 String* s,
 NumberStyles style,
 IFormatProvider* provider,
] double* result
public static function TryParse(
   s : String,
 style : NumberStyles,
 provider : IFormatProvider,
 result : double
) : Boolean;


A string containing a numberto convert.
The combination of one or more NumberStyles constants that indicate the permitted format of s.
An IFormatProvider that supplies culture-specific formatting information about s.
A double-precision floating-point number equivalent to the numeric value or symbol specified in s. If the return value is false, result is set to zero.

Return Value

true if s is converted successfully; otherwise, false.


The TryParse method is like the Parse method, except this method does not throw an exception if the conversion fails. If the conversion succeeds, the return value is true and the result parameter is set to the outcome of the conversion. If the conversion fails, the return value is false and the result parameter is set to zero.

The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or not a numeric value, the provider parameter does not yield a NumberFormatInfo object, or the style parameter is not a combination of bit flags from the NumberStyles enumeration.

The s parameter can contain PositiveInfinitySymbol, NegativeInfinitySymbol, NaNSymbol, or a string of the form:


Optional items are framed in square brackets ([ and ]). Items containing the term "digits" consist of a series of numeric characters ranging from 0 to 9.

A series of white space characters.
A negative sign or positive sign symbol.
A series of digits specifying the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. (For example, in some cultures a comma (,) separates groups of thousands.) Integral-digits can be absent if there are fractional-digits.
A culture-specific decimal point symbol.
A series of digits specifying the fractional part of the number.
An uppercase or lowercase character 'e', indicating exponential (scientific) notation.
A series of digits specifying an exponent.

Some examples of s are "100", "-123,456,789", "123.45e+6", "+500", "5e2", "3.1416", "600.", "-.123", and "-Infinity".

For more information about numeric formats, see the Formatting Overview topic.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Double Structure | Double Members | System Namespace | Formatting Overview | ToString