Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

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
[C#]
public static bool TryParse(
 string s,
 NumberStyles style,
 IFormatProvider provider,
   out double result
);
[C++]
public: static bool TryParse(
 String* s,
 NumberStyles style,
 IFormatProvider* provider,
   [
   Out
] double* result
);
[JScript]
public static function TryParse(
   s : String,
 style : NumberStyles,
 provider : IFormatProvider,
 result : double
) : Boolean;

Parameters

s
A string containing a numberto convert.
style
The combination of one or more NumberStyles constants that indicate the permitted format of s.
provider
An IFormatProvider that supplies culture-specific formatting information about s.
result
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.

Remarks

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:

[ws][sign]integral-digits[.[fractional-digits]][e[sign]exponential-digits][ws]

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.

ws
A series of white space characters.
sign
A negative sign or positive sign symbol.
integral-digits
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.
fractional-digits
A series of digits specifying the fractional part of the number.
'e'
An uppercase or lowercase character 'e', indicating exponential (scientific) notation.
exponential-digits
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.

Requirements

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.