System.Globalization.NumberStyles Enumeration

Assembly: Mscorlib.dll
Namespace: System.Globalization
Summary
Determines the styles permitted in numeric string arguments that are passed to the Parse methods of the numeric base type classes.
C# Syntax:
[Flags]
[Serializable]
public enum NumberStyles
Remarks
The symbols to use for currency symbol, thousands separator, decimal point indicator, and leading sign are specified by NumberFormatInfo.

The AllowCurrencySymbol and AllowDecimalPoint values determine whether a Parse method treats an instance of a numeric type as a currency or as a number and, therefore, whether to use the currency properties or the number properties of the associated NumberFormatInfo. For example, if AllowCurrencySymbol is specified, a Parse method uses currency properties, such as NumberFormatInfo.CurrencyDecimalSeparator and NumberFormatInfo.CurrencyGroupSeparator. However, if AllowDecimalPoint is specified, the method uses number properties, such as NumberFormatInfo.NumberDecimalSeparator and NumberFormatInfo.NumberGroupSeparator.

The attributes of NumberStyles are set by using the bitwise inclusive OR of the field flags. The Most Significant Bit (MSB) is the leftmost bit.

In the following table, the rows are the number styles with individual field flags and the columns are the composite number styles that combine individual field flags.

Under the composite number styles, a "1" means that the composite number style includes the individual number style in that row; a "0" means the composite number style does not include the individual number style in that row.

The hexadecimal representation of the composite number styles are listed in the last row of the table.



Any Currency Float Integer Number
AllowCurrencySymbol (0x0100) 1 1 0 0 0
AllowExponent (0x0080) 1 0 1 0 0
AllowThousands (0x0040) 1 1 0 0 1
AllowDecimalPoint (0x0020) 1 1 1 0 1
AllowParentheses (0x0010) 1 1 0 0 0
AllowTrailingSign (0x0008) 1 1 0 0 0
AllowLeadingSign (0x0004) 1 1 1 1 1
AllowTrailingWhite (0x0002) 1 1 1 1 1
AllowLeadingWhite (0x0001) 1 1 1 1 1
Hexadecimal -> 0x01ff 0x017f 0x00a7 0x0007 0x0067

The AllowExponent style is used for numeric strings in one of the following forms:

[-] m.dddddd E+ xx

[-] m.dddddd E- xx

[-] m.dddddd e+ xx

[-] m.dddddd e- xx

One or more non-zero digits (m) precede the decimal separator ("."). A minus sign ("-") can precede m. The Type performing the conversion determines the number of decimal places (dddddd) in the string, and maximum and minimum values for xx and m. The exponent (+ / - xx) consists of either a plus or minus sign followed by at least one digit.

See also:
System.Globalization Namespace | NumberFormatInfo

System.Globalization.NumberStyles Member List:

Public Fields
AllowCurrencySymbol Indicates that the numeric string is parsed as currency if it contains a currency symbol; otherwise, it is parsed as a number. Valid currency symbols are determined by the NumberFormatInfo.CurrencySymbol property of NumberFormatInfo.
AllowDecimalPoint Indicates that the numeric string can have a decimal point. Valid decimal point characters are determined by the NumberFormatInfo.NumberDecimalSeparator and NumberFormatInfo.CurrencyDecimalSeparator properties of NumberFormatInfo.
AllowExponent Indicates that the numeric string can be in exponential notation.
AllowHexSpecifier Indicates that the numeric string can have notation that signifies that the number is hexadecimal. Valid hexadecimal values include the numeric digits 0-9 and the hexadecimal digits A-F and a-f. Hexadecimal values can be left-padded with zeros. Strings parsed using this style are not permitted to be prefixed with "0x".
AllowLeadingSign Indicates that the numeric string can have a leading sign. Valid leading sign characters are determined by the NumberFormatInfo.PositiveSign and NumberFormatInfo.NegativeSign properties of NumberFormatInfo.
AllowLeadingWhite Indicates that a leading white-space character must be ignored during parsing. Valid white-space characters have the Unicode values U+0009, U+000A, U+000B, U+000C, U+000D, and U+0020.
AllowParentheses Indicates that the numeric string can have one pair of parentheses enclosing the number.
AllowThousands Indicates that the numeric string can have group separators; for example, separating the hundreds from the thousands. Valid group separator characters are determined by the NumberFormatInfo.NumberGroupSeparator and NumberFormatInfo.CurrencyGroupSeparator properties of NumberFormatInfo and the number of digits in each group is determined by the NumberFormatInfo.NumberGroupSizes and NumberFormatInfo.CurrencyGroupSizes properties of NumberFormatInfo.
AllowTrailingSign Indicates that the numeric string can have a trailing sign. Valid trailing sign characters are determined by the NumberFormatInfo.PositiveSign and NumberFormatInfo.NegativeSign properties of NumberFormatInfo.
AllowTrailingWhite Indicates that trailing white-space character must be ignored during parsing. Valid white-space characters have the Unicode values U+0009, U+000A, U+000B, U+000C, U+000D, and U+0020.
Any Indicates that all the AllowXXX bit styles are used. This is a composite number style.
Currency Indicates that all styles except AllowExponent are used. This is a composite number style.
Float Indicates that the AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowDecimalPoint, and AllowExponent styles are used. This is a composite number style.
HexNumber Indicates that the AllowLeadingWhite, AllowTrailingWhite, and AllowHexSpecifier styles are used. This is a composite number style.
Integer Indicates that the AllowLeadingWhite, AllowTrailingWhite, and AllowLeadingSign styles are used. This is a composite number style.
None Indicates that none of the bit styles are allowed.
Number Indicates that the AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowTrailingSign, AllowDecimalPoint, and AllowThousands styles are used. This is a composite number style.

Hierarchy:


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.