Decimal::Parse Method (String^, NumberStyles, IFormatProvider^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format.

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

static Decimal Parse(
	String^ s,
	NumberStyles style,
	IFormatProvider^ provider


Type: System::String^

The string representation of the number to convert.

Type: System.Globalization::NumberStyles

A bitwise combination of NumberStyles values that indicates the style elements that can be present in s. A typical value to specify is Number.

Type: System::IFormatProvider^

An IFormatProvider object that supplies culture-specific information about the format of s.

Return Value

Type: System::Decimal

The Decimal number equivalent to the number contained in s as specified by style and provider.

Exception Condition

s is not in the correct format.


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


s is null.


style is not a NumberStyles value.


style is the AllowHexSpecifier value.

The style parameter defines the allowable format of 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:

Depending on the value of style, the s parameter may include the following elements:


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




A culture-specific currency symbol. Its position in the string is defined by the CurrencyNegativePattern and CurrencyPositivePattern properties of the NumberFormatInfo object returned by the GetFormat method of the provider parameter. The currency symbol can appear in s if style includes the NumberStyles::AllowCurrencySymbol flag.


Optional white space. 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.


An optional sign. 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 sequence of digits ranging from 0 to 9.


A culture-specific thousands separator symbol. The thousands separator of the culture defined by provider can appear in s if style includes the NumberStyles::AllowThousands flag.


A culture-specific decimal point symbol. The decimal point symbol of the culture defined by provider can appear in s if style includes the NumberStyles::AllowDecimalPoint flag.


A sequence of digits ranging from 0 to 9. Fractional digits can appear in s only if style includes the NumberStyles::AllowDecimalPoint flag.


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

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

NumberStyles value

Elements permitted in s in addition to digits


The digits element only.


The . and fractional-digits elements.


The s parameter can also use exponential notation. This flag supports values in the form digitsEdigits; additional flags are needed to successfully parse strings with elements such 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 , element.


The $ element.


All. The s parameter 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 .symbol. The s parameter can also use exponential notation.


The ws, sign, ,, and . elements.


All styles, except s cannot represent a hexadecimal number.

The provider parameter is an IFormatProvider implementation, such as a NumberFormatInfo or CultureInfo object. The provider parameter supplies culture-specific information used in parsing. If provider is null, the thread current culture is used.

A Decimal object has 29 digits of precision. If s represents a number that has more than 29 digits, but has a fractional part and is within the range of MaxValue and MinValue, the number is rounded, not truncated, to 29 digits using rounding to nearest.

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 a variety of style and provider parameters to parse the string representations of Decimal values.

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

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top