Double.Parse Method (String)
Converts the string representation of a number to its double-precision floating-point number equivalent.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- s
-
Type:
System.String
A string that contains a number to convert.
Return Value
Type: System.DoubleA double-precision floating-point number that is equivalent to the numeric value or symbol specified in s.
| Exception | Condition |
|---|---|
| ArgumentNullException | s is null. |
| FormatException | s does not represent a number in a valid format. |
| OverflowException |
The s parameter can contain the current culture's NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:
[ws][sign][integral-digits[,]]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]
Elements in square brackets ([ and ]) are optional. The following table describes each element.
Element | Description |
|---|---|
ws | A series of white-space characters. |
sign | A negative sign symbol (-) or a positive sign symbol (+). Only a leading sign can be used. |
integral-digits | A series of digits ranging from 0 to 9 that specify 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. The integral-digits element can be absent if the string contains the fractional-digits element. |
, | A culture-specific thousands separator symbol. |
. | A culture-specific decimal point symbol. |
fractional-digits | A series of digits ranging from 0 to 9 that specify the fractional part of the number. |
E | The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. |
exponential-digits | A series of digits ranging from 0 to 9 that specify an exponent. |
The s parameter is interpreted using a combination of the NumberStyles.Float and NumberStyles.AllowThousands flags. This means that white space and thousands separators are allowed, for example, while currency symbols are not. For finer control over which style elements are permitted in s for the parse operation to succeed, call the Double.Parse(String, NumberStyles) or the Double.Parse(String, NumberStyles, IFormatProvider) method.
The s parameter is interpreted using the formatting information in a NumberFormatInfo object that is initialized for the current thread culture. For more information, see CurrentInfo. To parse a string using the formatting information of some other culture, call the Double.Parse(String, IFormatProvider) or Double.Parse(String, NumberStyles, IFormatProvider) method.
Ordinarily, if you pass the Double.Parse method a string that is created by calling the Double.ToString method, the original Double value is returned. However, because of a loss of precision, the values may not be equal. In addition, attempting to parse the string representation of either MinValue or MaxValue throws an OverflowException, as the following example illustrates.
If a separator is encountered in the s parameter during a parse operation, and the applicable currency or number decimal and group separators are the same, the parse operation assumes that the separator is a decimal separator rather than a group separator. For more information about separators, see CurrencyDecimalSeparator, NumberDecimalSeparator, CurrencyGroupSeparator, and NumberGroupSeparator.
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1