This documentation is archived and is not being maintained.

Double.Parse Method (String, NumberStyles, IFormatProvider)

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

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

public static double Parse (
	string s,
	NumberStyles style,
	IFormatProvider provider
public static double Parse (
	String s, 
	NumberStyles style, 
	IFormatProvider provider
public static function Parse (
	s : String, 
	style : NumberStyles, 
	provider : IFormatProvider
) : double



A string containing a number to convert.


A bitwise combination of NumberStyles values that indicates the permitted format of s. A typical value to specify is Float combined with AllowThousands.


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


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


s is not a numeric value.


style is not a NumberStyles value.


style is the AllowHexSpecifier value.


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

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".

This version of the Parse method uses the specified NumberStyles and number formatting information. 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.

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

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 code example illustrates the use of Parse, taking a String, an IFormatProvider, and a NumberStyles as parameters:

public class Temperature {
    /// <summary>
    /// Parses the temperature from a string in form
    /// [ws][sign]digits['F|'C][ws]
    /// </summary>
    public static Temperature Parse(string s, NumberStyles styles, IFormatProvider provider) {
        Temperature temp = new Temperature();

        if( s.TrimEnd(null).EndsWith("'F") ) {
            temp.Value = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
        else if( s.TrimEnd(null).EndsWith("'C") ) {
            temp.Celsius = Double.Parse( s.Remove(s.LastIndexOf('\''), 2), styles, provider);
        else {
            temp.Value = Double.Parse(s, styles, provider);

        return temp;

    // The value holder
    protected double m_value;

    public double Value {
        get {
            return m_value;
        set {
            m_value = value;

    public double Celsius {
        get {
            return (m_value-32.0)/1.8;
        set {
            m_value = 1.8*value+32.0;

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0