다음을 통해 공유


NumberFormatInfo 클래스

Culture에 따라 숫자 값의 서식이 지정되고 표시되는 방법을 정의합니다.

네임스페이스: System.Globalization
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class NumberFormatInfo
    Implements ICloneable, IFormatProvider
‘사용 방법
Dim instance As NumberFormatInfo
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public sealed class NumberFormatInfo : ICloneable, IFormatProvider
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public ref class NumberFormatInfo sealed : ICloneable, IFormatProvider
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class NumberFormatInfo implements ICloneable, IFormatProvider
SerializableAttribute 
ComVisibleAttribute(true) 
public final class NumberFormatInfo implements ICloneable, IFormatProvider

설명

이 클래스에는 통화, 소수 구분 기호, 기타 숫자 기호 등이 들어 있습니다.

특정 culture에 대한 NumberFormatInfo를 만들려면 해당 culture에 대한 CultureInfo를 만든 다음 CultureInfo.NumberFormat 속성을 검색합니다. 현재 스레드의 culture에 대한 NumberFormatInfo를 만들려면 CurrentInfo 속성을 사용합니다. 불변 culture에 대한 NumberFormatInfo를 만들려면 읽기 전용 버전의 InvariantInfo 속성을 사용하거나 쓰기 가능한 버전의 NumberFormatInfo 생성자를 사용합니다. 중립 culture에 대한 NumberFormatInfo를 만들 수 없습니다.

사용자는 제어판의 국가별 설정 옵션을 사용하여 Windows의 현재 culture와 관련된 일부 값을 재정의할 수 있습니다. 예를 들어, 날짜를 다른 형식으로 표시하거나 해당 culture의 기본 통화 단위가 아닌 다른 통화 단위를 사용할 수 있습니다. CultureInfo.UseUserOverride 속성을 true로 설정한 경우 CultureInfo.DateTimeFormat 인스턴스, CultureInfo.NumberFormat 인스턴스 및 CultureInfo.TextInfo 인스턴스의 속성 또한 사용자 설정에서 검색됩니다. 사용자 설정이 CultureInfo에 연결된 culture와 호환되지 않는 경우(예: 선택한 달력이 OptionalCalendars 중 하나가 아닌 경우) 해당 메서드의 결과와 속성 값은 정의되지 않습니다.

숫자 값은 NumberFormatInfo 속성에 저장된 표준 또는 사용자 지정 패턴을 사용하여 서식이 지정됩니다. 값이 표시되는 방법을 수정하려면 속성에 사용자 지정 패턴을 저장할 수 있도록 NumberFormatInfo가 쓰기 가능해야 합니다.

다음 표에서는 각 표준 패턴과 표준 패턴을 수정하기 위해 설정할 수 있는 관련 NumberFormatInfo 속성에 대한 표준 서식 문자를 보여 줍니다.

서식 문자

설명 및 관련 속성

c, C

통화 형식 CurrencyNegativePattern, CurrencyPositivePattern, CurrencySymbol, CurrencyGroupSizes, CurrencyGroupSeparator, CurrencyDecimalDigits, CurrencyDecimalSeparator.

d, D

10진수 형식

e, E

공학용(지수) 형식

f, F

고정 소수점 형식

g, G

일반 형식

n, N

숫자 형식 NumberNegativePattern, NumberGroupSizes, NumberGroupSeparator, NumberDecimalDigits, NumberDecimalSeparator.

r, R

문자열로 변환된 숫자가 다시 숫자로 변환될 경우 동일한 값을 갖게 하는 라운드트립 형식

x, X

16진수 형식

중립 culture가 아닌 불변 culture나 특정 culture에 대해서만 DateTimeFormatInfo 또는 NumberFormatInfo를 만들 수 있습니다. 불변 culture, 특정 culture 및 중립 culture에 대한 자세한 내용은 CultureInfo 클래스를 참조하십시오.

이 클래스는 NumberFormatInfo 개체를 복제할 수 있는 ICloneable 인터페이스를 구현합니다. 또한 응용 프로그램에 형식 지정 정보를 제공하는 IFormatProvider를 구현합니다.

예제

다음 코드 예제에서는 해당하는 CultureInfo에 대한 NumberFormatInfo를 가져오고 NumberFormatInfo를 사용하여 해당 culture에 대한 숫자 서식 정보를 쿼리하는 방법을 보여 줍니다.

using System;
using System.Globalization;
using System.Text;

public sealed class App 
{
    static void Main() 
    {
        StringBuilder sb = new StringBuilder();

        // Loop through all the specific cultures known to the CLR.
        foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures)) 
        {
            // Only show the currency symbols for cultures that speak English.
            if (ci.TwoLetterISOLanguageName != "en") continue;
             
            // Display the culture name and currency symbol.
            NumberFormatInfo nfi = ci.NumberFormat;
            sb.AppendFormat("The currency symbol for '{0}' is '{1}'",
                ci.DisplayName, nfi.CurrencySymbol);
            sb.AppendLine();
        }
        Console.WriteLine(sb.ToString());
    }
}

// This code produces the following output.
//
// The currency symbol for 'English (United States)' is '$'
// The currency symbol for 'English (United Kingdom)' is ''
// The currency symbol for 'English (Australia)' is '$'
// The currency symbol for 'English (Canada)' is '$'
// The currency symbol for 'English (New Zealand)' is '$'
// The currency symbol for 'English (Ireland)' is '?'
// The currency symbol for 'English (South Africa)' is 'R'
// The currency symbol for 'English (Jamaica)' is 'J$'
// The currency symbol for 'English (Caribbean)' is '$'
// The currency symbol for 'English (Belize)' is 'BZ$'
// The currency symbol for 'English (Trinidad and Tobago)' is 'TT$'
// The currency symbol for 'English (Zimbabwe)' is 'Z$'
// The currency symbol for 'English (Republic of the Philippines)' is 'Php'
using namespace System;
using namespace System::Globalization;
using namespace System::Text;

int main()
{
    StringBuilder^ builder = gcnew StringBuilder();

    // Loop through all the specific cultures known to the CLR.
    for each(CultureInfo^ culture in 
        CultureInfo::GetCultures (CultureTypes::SpecificCultures)) 
    {
        // Only show the currency symbols for cultures 
        // that speak English.
        if (culture->TwoLetterISOLanguageName == "en")
        {
            // Display the culture name and currency symbol.
            NumberFormatInfo^ numberFormat = culture->NumberFormat;
            builder->AppendFormat("The currency symbol for '{0}'"+
                "is '{1}'",culture->DisplayName,
                numberFormat->CurrencySymbol);
            builder->AppendLine();
        }
    }
    Console::WriteLine(builder);
}

// This code produces the following output.
//
// The currency symbol for 'English (United States)' is '$'
// The currency symbol for 'English (United Kingdom)' is 'Ј'
// The currency symbol for 'English (Australia)' is '$'
// The currency symbol for 'English (Canada)' is '$'
// The currency symbol for 'English (New Zealand)' is '$'
// The currency symbol for 'English (Ireland)' is '?'
// The currency symbol for 'English (South Africa)' is 'R'
// The currency symbol for 'English (Jamaica)' is 'J$'
// The currency symbol for 'English (Caribbean)' is '$'
// The currency symbol for 'English (Belize)' is 'BZ$'
// The currency symbol for 'English (Trinidad and Tobago)' is 'TT$'
// The currency symbol for 'English (Zimbabwe)' is 'Z$'
// The currency symbol for 'English (Republic of the Philippines)' is 'Php'

상속 계층 구조

System.Object
  System.Globalization.NumberFormatInfo

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

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에서 지원

참고 항목

참조

NumberFormatInfo 멤버
System.Globalization 네임스페이스
Decimal
CultureInfo 클래스

기타 리소스

형식 지정 개요