NumberStyles 열거형
숫자 기본 형식 클래스 Parse 메서드에 전달되는 숫자 문자열에서 사용할 수 있는 스타일을 결정합니다.
이 열거형에는 멤버 값를 비트로 조합할 수 있는 FlagsAttribute 특성이 있습니다.
네임스페이스: System.Globalization
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration NumberStyles
‘사용 방법
Dim instance As NumberStyles
[SerializableAttribute]
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum NumberStyles
[SerializableAttribute]
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum class NumberStyles
/** @attribute SerializableAttribute() */
/** @attribute FlagsAttribute() */
/** @attribute ComVisibleAttribute(true) */
public enum NumberStyles
SerializableAttribute
FlagsAttribute
ComVisibleAttribute(true)
public enum NumberStyles
멤버
멤버 이름 | 설명 | |
---|---|---|
![]() |
AllowCurrencySymbol | 숫자 문자열에 통화 기호가 들어 있는 경우 통화로 구문 분석하고, 그렇지 않으면 숫자로 구문 분석함을 나타냅니다. 유효한 통화 기호는 NumberFormatInfo의 CurrencySymbol 속성으로 결정됩니다. |
![]() |
AllowDecimalPoint | 숫자 문자열에 소수점이 있을 수 있음을 나타냅니다. 유효한 소수점 문자는 NumberFormatInfo의 NumberDecimalSeparator 및 CurrencyDecimalSeparator 속성으로 결정됩니다. |
![]() |
AllowExponent | 숫자 문자열에 지수 표시가 있을 수 있음을 나타냅니다. |
![]() |
AllowHexSpecifier | 숫자 문자열이 16진수 값을 나타낸다는 것을 나타냅니다. 유효한 16진수 값은 0부터 9까지의 숫자와 A부터 F 및 a부터 f까지의 16진 문자를 포함합니다. 16진수 값은 왼쪽이 0으로 채워질 수 있습니다. 이 스타일을 사용하여 구문 분석된 문자열에는 "0x"를 접두사로 붙일 수 없습니다. |
![]() |
AllowLeadingSign | 숫자 문자열에 선행 부호가 있을 수 있음을 나타냅니다. 유효한 선행 부호 문자는 NumberFormatInfo의 PositiveSign 및 NegativeSign 속성으로 결정됩니다. |
![]() |
AllowLeadingWhite | 구분 분석 중에 선행 공백 분자를 무시해야 함을 나타냅니다. 공백 문자의 유니코드 값은 U+0009, U+000A, U+000B, U+000C, U+000D 및 U+0020입니다. |
![]() |
AllowParentheses | 숫자 문자열에 숫자를 둘러싸는 한 쌍의 괄호가 있을 수 있음을 나타냅니다. |
![]() |
AllowThousands | 숫자 문자열에 100 단위나 1000 단위를 구분하는 그룹 구분 기호가 있을 수 있음을 나타냅니다. 유효한 그룹 구분 문자는 NumberFormatInfo의 NumberGroupSeparator 및 CurrencyGroupSeparator 속성으로 결정되며 각 그룹의 자릿수는 NumberFormatInfo의 NumberGroupSizes 및 CurrencyGroupSizes 속성으로 결정됩니다. |
![]() |
AllowTrailingSign | 숫자 문자열에 후행 부호가 있을 수 있음을 나타냅니다. 유효한 후행 부호 문자는 NumberFormatInfo의 PositiveSign 및 NegativeSign 속성으로 결정됩니다. |
![]() |
AllowTrailingWhite | 구분 분석 중에 후행 공백 분자를 무시해야 함을 나타냅니다. 공백 문자의 유니코드 값은 U+0009, U+000A, U+000B, U+000C, U+000D 및 U+0020입니다. |
![]() |
Any | AllowHexSpecifier를 제외한 모든 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다. |
![]() |
Currency | AllowExponent 및 AllowHexSpecifier를 제외한 모든 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다. |
![]() |
Float | AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowDecimalPoint 및 AllowExponent 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다. |
![]() |
HexNumber | AllowLeadingWhite, AllowTrailingWhite 및 AllowHexSpecifier 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다. |
![]() |
Integer | AllowLeadingWhite, AllowTrailingWhite 및 AllowLeadingSign 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다. |
![]() |
None | 모든 비트 스타일을 사용할 수 없음을 나타냅니다. |
![]() |
Number | AllowLeadingWhite, AllowTrailingWhite, AllowLeadingSign, AllowTrailingSign, AllowDecimalPoint 및 AllowThousands 스타일을 사용함을 나타냅니다. 이것은 복합 숫자 스타일입니다. |
설명
NumberFormatInfo로 지정되는 통화 기호, 1000 단위 구분 기호, 소수점 기호, 선행 부호에 사용할 기호입니다 .
AllowCurrencySymbol 및 AllowDecimalPoint 값을 통해 Parse 메서드는 숫자 형식의 인스턴스를 통화 또는 숫자로 볼 지를 결정하므로, 관련 NumberFormatInfo의 통화 속성 또는 숫자 속성을 사용할 지를 결정할 수 있습니다. 예를 들어, AllowCurrencySymbol을 지정한 경우 Parse 메서드는 CurrencyDecimalSeparator 및 CurrencyGroupSeparator와 같은 통화 속성을 사용합니다. 하지만 AllowDecimalPoint를 지정한 경우 해당 메서드는 NumberDecimalSeparator 및 NumberGroupSeparator와 같은 숫자 속성을 사용합니다.
필드 플래그의 비트 OR 연산을 사용하여 NumberStyles 특성을 설정합니다. MSB(최상위 비트)는 가장 왼쪽에 있는 비트입니다.
다음 표에서 행은 개별 필드 플래그를 사용한 숫자 스타일이며 열은 개별 필드 플래그를 조합한 복합 숫자 스타일입니다.
복합 숫자 스타일에서 "1"은 해당 행에 개별 숫자 스타일이 포함된다는 의미이고, "0"은 해당 행에 개별 숫자 스타일이 포함되지 않는다는 의미입니다.
표의 마지막 행에 복합 숫자 스타일의 16진수 표현이 나열되어 있습니다.
모두 |
통화 |
Float |
정수 |
숫자 |
HexNumber |
|
---|---|---|---|---|---|---|
AllowHexSpecifier (0x0200) |
0 |
0 |
0 |
0 |
0 |
1 |
AllowCurrencySymbol (0x0100) |
1 |
1 |
0 |
0 |
0 |
0 |
AllowExponent (0x0080) |
1 |
0 |
1 |
0 |
0 |
0 |
AllowThousands (0x0040) |
1 |
1 |
0 |
0 |
1 |
0 |
AllowDecimalPoint (0x0020) |
1 |
1 |
1 |
0 |
1 |
0 |
AllowParentheses (0x0010) |
1 |
1 |
0 |
0 |
0 |
0 |
AllowTrailingSign (0x0008) |
1 |
1 |
0 |
0 |
1 |
0 |
AllowLeadingSign (0x0004) |
1 |
1 |
1 |
1 |
1 |
0 |
AllowTrailingWhite (0x0002) |
1 |
1 |
1 |
1 |
1 |
1 |
AllowLeadingWhite (0x0001) |
1 |
1 |
1 |
1 |
1 |
1 |
(0x1ff) |
(0x17f) |
(0x0a7) |
(0x007) |
(0x06f) |
(0x203) |
다음 형식 중 하나의 숫자 문자열에 AllowExponent 스타일이 사용됩니다.
[-] m . dddddd E+ xx
[-] m . dddddd E- xx
[-] m . dddddd e+ xx
[-] m . dddddd e- xx
0이 아닌 하나 이상의 숫자( m )가 소수 구분 기호(".") 앞에 나옵니다. 빼기("-") 기호가 m 앞에 올 수 있습니다. 변환을 수행하는 Type은 문자열에서 소수 자릿수( dddddd )와 xx 및 m에 대한 최대 및 최소값을 결정합니다. 지수(+ / - xx )는 더하기나 빼기 기호 다음에 하나 이상의 숫자가 나옵니다.
예제
이 예제에서는 다양한 NumberStyles 플래그를 사용하여 문자열을 32비트 정수로 구문 분석하는 방법을 보여 줍니다.
using System;
using System.Text;
using System.Globalization;
public sealed class App
{
static void Main()
{
// Parse the string as a hex value and display the value as a decimal.
String num = "A";
int val = int.Parse(num, NumberStyles.HexNumber);
Console.WriteLine("{0} in hex = {1} in decimal.", num, val);
// Parse the string, allowing a leading sign, and ignoring leading and trailing white spaces.
num = " -45 ";
val = int.Parse(num, NumberStyles.AllowLeadingSign |
NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);
Console.WriteLine("'{0}' parsed to an int is '{1}'.", num, val);
// Parse the string, allowing parentheses, and ignoring leading and trailing white spaces.
num = " (37) ";
val = int.Parse(num, NumberStyles.AllowParentheses | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite);
Console.WriteLine("'{0}' parsed to an int is '{1}'.", num, val);
}
}
// This code produces the following output.
//
// A in hex = 10 in decimal.
// ' -45 ' parsed to an int is '-45'.
// ' (37) ' parsed to an int is '-37'.
using namespace System;
using namespace System::Text;
using namespace System::Globalization;
int main()
{
// Parse the string as a hex value and display the
// value as a decimal.
String^ numberString = "A";
int stringValue = Int32::Parse(numberString, NumberStyles::HexNumber);
Console::WriteLine("{0} in hex = {1} in decimal.",
numberString, stringValue);
// Parse the string, allowing a leading sign, and ignoring
// leading and trailing white spaces.
numberString = " -45 ";
stringValue =Int32::Parse(numberString, NumberStyles::AllowLeadingSign |
NumberStyles::AllowLeadingWhite | NumberStyles::AllowTrailingWhite);
Console::WriteLine("'{0}' parsed to an int is '{1}'.",
numberString, stringValue);
// Parse the string, allowing parentheses, and ignoring
// leading and trailing white spaces.
numberString = " (37) ";
stringValue = Int32::Parse(numberString, NumberStyles::AllowParentheses |
NumberStyles::AllowLeadingSign | NumberStyles::AllowLeadingWhite |
NumberStyles::AllowTrailingWhite);
Console::WriteLine("'{0}' parsed to an int is '{1}'.",
numberString, stringValue);
}
// This code produces the following output.
//
// A in hex = 10 in decimal.
// ' -45 ' parsed to an int is '-45'.
// ' (37) ' parsed to an int is '-37'.
플랫폼
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
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원