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(非数字)值的字符串。

NativeDigits

获取或设置与西文数字 0 到 9 等同的本机数字的字符串数组。

NegativeInfinitySymbol

获取或设置表示负无穷大的字符串。

NegativeSign

获取或设置表示关联数字是负值的字符串。

NumberDecimalDigits

获取或设置在数值中使用的小数位数。

NumberDecimalSeparator

获取或设置在数值中用作小数分隔符的字符串。

NumberGroupSeparator

获取或设置在数值中隔开小数点左边的位数组的字符串。

NumberGroupSizes

获取或设置数值中小数点左边每一组的位数。

NumberNegativePattern

获取或设置负数值的格式模式。

PercentDecimalDigits

获取或设置在百分比值中使用的小数位数。

PercentDecimalSeparator

获取或设置在百分比值中用作小数点分隔符的字符串。

PercentGroupSeparator

获取或设置在百分比值中隔离小数点左边数字组的字符串。

PercentGroupSizes

获取或设置在百分比值中小数点左边每一组的位数。

PercentNegativePattern

获取或设置负百分比值的格式模式。

PercentPositivePattern

获取或设置正百分比值的格式模式。

PercentSymbol

获取或设置用作百分比符号的字符串。

PerMilleSymbol

获取或设置用作千分比符号的字符串。

PositiveInfinitySymbol

获取或设置表示正无穷大的字符串。

PositiveSign

获取或设置指示关联数字是正值的字符串。

方法

Clone()

创建 NumberFormatInfo 对象的浅表副本。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetFormat(Type)

获取提供数字格式化服务的指定类型的对象。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetInstance(IFormatProvider)

获取与指定 NumberFormatInfo 关联的 IFormatProvider

GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ReadOnly(NumberFormatInfo)

返回只读的 NumberFormatInfo 包装。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅