This documentation is archived and is not being maintained.

Single.Parse Method (String, NumberStyles, IFormatProvider)

Updated: August 2009

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

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

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


Type: System.String

A string that contains a number to convert.

Type: System.Globalization.NumberStyles

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

Type: System.IFormatProvider

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

Return Value

Type: System.Single
A single-precision floating-point number equivalent to the numeric value or symbol specified in s.


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


s is not a numeric value.


style is not a NumberStyles value.


style is the NumberStyles.AllowHexSpecifier value.

The style parameter defines the style elements (such as white space, thousands separators, and currency symbols) that are allowed in the s parameter for the parse operation to succeed. It must be a combination of bit flags from the NumberStyles enumeration. The following NumberStyles members are not supported:

The s parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, or NumberFormatInfo.NaNSymbol for the culture specified by provider. Depending on the value of style, it can also take the form:

[ws] [$] [sign][integral-digits,]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]

Elements framed in square brackets ([ and ]) are optional. The following table describes each element.




A series of white-space characters. White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingWhite flag.


A culture-specific currency symbol. Its position in the string is defined by the NumberFormatInfo.CurrencyNegativePattern and NumberFormatInfo.CurrencyPositivePattern properties of the current culture. The current culture's currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag.


A negative sign symbol (-) or a positive sign symbol (+). The sign can appear at the beginning of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingSign flag. Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag.


A series of digits ranging from 0 to 9 that specify the integral part of the number. The integral-digits element can be absent if the string contains the fractional-digits element.


A culture-specific group separator. The current culture's group separator symbol can appear in s if style includes the NumberStyles.AllowThousands flag


A culture-specific decimal point symbol. The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag.


A series of digits ranging from 0 to 9 that specify the fractional part of the number. Fractional digits can appear in s if style includes the NumberStyles.AllowDecimalPoint flag.


The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag.


A series of digits ranging from 0 to 9 that specify an exponent.

A string with digits only (which corresponds to the NumberStyles.None style) always parses successfully. The remaining System.Globalization.NumberStyles members control elements that may be present, but are not required to be present, in the input string. The following table indicates how individual NumberStyles flags affect the elements that may be present in s.

NumberStyles value

Elements permitted in s in addition to digits


The integral-digits element only.


The decimal point (.) and fractional-digits elements.


The "e" or "E" character, which indicates exponential notation. This flag by itself supports values in the form digitsEdigits; additional flags are needed to successfully parse strings with such elements as positive or negative signs and decimal point symbols.


The ws element at the beginning of s.


The ws element at the end of s.


The sign element at the beginning of s.


The sign element at the end of s.


The sign element in the form of parentheses enclosing the numeric value.


The thousands separator (,) element.


The currency ($) element.


All elements. However, s cannot represent a hexadecimal number or a number in exponential notation.


The ws element at the beginning or end of s, sign at the beginning of s, and the decimal point (.) symbol. The s parameter can also use exponential notation.


The ws, sign, thousands separator (,) and decimal point (.) elements.


All elements. However, s cannot represent a hexadecimal number.

The provider parameter is an IFormatProvider implementation. Its GetFormat method returns a NumberFormatInfo object that provides culture-specific information about the format of value. Typically, provider can be any one of the following:

If provider is a null reference (Nothing in Visual Basic), the NumberFormatInfo object for the current 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 uses the Parse(String, NumberStyles, IFormatProvider) method to parse the string representations of Single values. Each string in an array is parsed using the formatting conventions of the en-US, nl-NL, and a custom culture. The custom culture defines its group separator symbol as the underscore ("_") and its group size as two.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0




August 2009

Revised extensively.

Information enhancement.