Export (0) Print
Expand All

Double.Parse Method (String, IFormatProvider)

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

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static double Parse (
	string s,
	IFormatProvider provider
)
public static double Parse (
	String s, 
	IFormatProvider provider
)
public static function Parse (
	s : String, 
	provider : IFormatProvider
) : double
Not applicable.

Parameters

s

A string containing a number to convert.

provider

An IFormatProvider that supplies culture-specific formatting information about s.

Return Value

A double-precision floating-point number equivalent to the numeric value or symbol specified in s.

Exception typeCondition

ArgumentNullException

s is a null reference (Nothing in Visual Basic).

FormatException

s is not a number in a valid format.

OverflowException

s represents a number less than MinValue or greater than MaxValue.

This overload of the Parse(String,IFormatProvider) method is typically used to convert text that can be formatted in a variety of ways to a Double value. For example, it can be used to convert the text entered by a user into an HTML text box to a numeric value.

The s parameter is interpreted using a combination of the NumberStyles.Float and NumberStyles.AllowThousands flags. The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.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.

Element

Description

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.

For more information about numeric formats, see the [<topic://cpConFormattingOverview>] topic.

The provider parameter is an IFormatProvider implementation whose GetFormat method returns a NumberFormatInfo object that supplies culture-specific information used in interpreting the format of s. Typically, it is a NumberFormatInfo object or a CultureInfo object. If provider is a null reference (Nothing in Visual Basic) or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.

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.

The following example is the button click event handler of a Web form. It uses the array returned by the HttpRequest.UserLanguages property to determine the user's locale. It then instantiates a CultureInfo object that corresponds to that locale. The NumberFormatInfo object that belongs to that CultureInfo object is then passed to the Parse(String,IFormatProvider) method to convert the user's input to a Double value.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft