NumberFormatInfo 類別

定義

提供文化特性特定的格式和剖析數值資訊。

public ref class NumberFormatInfo sealed : IFormatProvider
public ref class NumberFormatInfo sealed : ICloneable, IFormatProvider
public sealed class NumberFormatInfo : IFormatProvider
public sealed class NumberFormatInfo : ICloneable, IFormatProvider
[System.Serializable]
public sealed class NumberFormatInfo : ICloneable, IFormatProvider
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class NumberFormatInfo : ICloneable, IFormatProvider
type NumberFormatInfo = class
    interface IFormatProvider
type NumberFormatInfo = class
    interface ICloneable
    interface IFormatProvider
[<System.Serializable>]
type NumberFormatInfo = class
    interface ICloneable
    interface IFormatProvider
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type NumberFormatInfo = class
    interface ICloneable
    interface IFormatProvider
Public NotInheritable Class NumberFormatInfo
Implements IFormatProvider
Public NotInheritable Class NumberFormatInfo
Implements ICloneable, IFormatProvider
繼承
NumberFormatInfo
屬性
實作

範例

下列範例示範如何擷取 NumberFormatInfo 對應 CultureInfo 物件的物件,並使用擷取的對象來查詢特定文化特性的數位格式資訊。

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'
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'
Imports System.Globalization
Imports System.Text

Public Module Example
   Public Sub Main() 
      Dim sb As New StringBuilder()

      ' Loop through all the specific cultures known to the CLR.
      For Each ci In CultureInfo.GetCultures(CultureTypes.SpecificCultures) 
         ' Only show the currency symbols for cultures that speak English.
         If ci.TwoLetterISOLanguageName <> "en" Then Continue For

         ' Display the culture name and currency symbol.
         Dim nfi As NumberFormatInfo = ci.NumberFormat
         sb.AppendFormat("The currency symbol for '{0}' is '{1}'",
                         ci.DisplayName, nfi.CurrencySymbol)
         sb.AppendLine()
      Next
      Console.WriteLine(sb.ToString())
   End Sub
End Module
' The example displays output like the following:
'       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'
'       The currency symbol for 'English (India)' is 'Rs.'
'       The currency symbol for 'English (Malaysia)' is 'RM'
'       The currency symbol for 'English (Singapore)' is '$'

備註

如需此 API 的詳細資訊,請參閱 NumberFormatInfo 的補充 API 備註

建構函式

NumberFormatInfo()

初始化與文化特性無關 (非變異) 之 NumberFormatInfo 類別的可寫入新執行個體。

屬性

CurrencyDecimalDigits

取得或設定要在貨幣值中使用的小數位數。

CurrencyDecimalSeparator

取得或設定要做為貨幣值中小數分隔符號的字串。

CurrencyGroupSeparator

取得或設定分隔貨幣值中小數點左邊數字群組的字串。

CurrencyGroupSizes

取得或設定貨幣值內小數點左邊數字的各個群組中的位數。

CurrencyNegativePattern

取得或設定負數貨幣值的格式模式。

CurrencyPositivePattern

取得或設定正數貨幣值的格式模式。

CurrencySymbol

取得或設定要做為貨幣符號的字串。

CurrentInfo

取得根據目前文化特性格式化值的唯讀 NumberFormatInfo

DigitSubstitution

取得或設定數值,指定圖形使用者介面顯示數字圖案的方式。

InvariantInfo

取得與文化特性無關 (非變異) 的唯讀 NumberFormatInfo 物件。

IsReadOnly

取得值,表示這個 NumberFormatInfo 物件是否為唯讀。

NaNSymbol

取得或設定代表 IEEE NaN (Not a Number) 值的字串。

NativeDigits

取得或設定字串陣列,其中包含對等於西方數字 0 到 9 之當地慣用的數字。

NegativeInfinitySymbol

取得或設定代表負無限大的字串。

NegativeSign

取得或設定代表相關數字為負數的字串。

NumberDecimalDigits

取得或設定要在數值中使用的小數位數。

NumberDecimalSeparator

取得或設定要做為數值中小數分隔符號的字串。

NumberGroupSeparator

取得或設定分隔數值中小數點左邊數字群組的字串。

NumberGroupSizes

取得或設定數值內小數點左邊數字的各個群組中的位數。

NumberNegativePattern

取得或設定負數值的格式模式。

PercentDecimalDigits

取得或設定要在百分比值中使用的小數位數。

PercentDecimalSeparator

取得或設定要做為百分比值中小數分隔符號使用的字串。

PercentGroupSeparator

取得或設定百分比值中分隔小數點左邊數字群組的字串。

PercentGroupSizes

取得或設定百分比值內小數點左邊數字的各個群組中的位數。

PercentNegativePattern

取得或設定負數百分比值的格式模式。

PercentPositivePattern

取得或設定正數百分比值的格式模式。

PercentSymbol

取得或設定要當做百分比符號的字串。

PerMilleSymbol

取得或設定要當做千分之一符號的字串。

PositiveInfinitySymbol

取得或設定代表正無限大的字串。

PositiveSign

取得或設定用來表示相關數字為正數的字串。

方法

Clone()

建立 NumberFormatInfo 物件的淺層複本 (Shallow Copy)。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetFormat(Type)

取得指定類型的物件,以提供數字格式化服務。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetInstance(IFormatProvider)

取得與指定的 NumberFormatInfo 相關聯的 IFormatProvider

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ReadOnly(NumberFormatInfo)

傳回唯讀的 NumberFormatInfo 包裝函式。

ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱