Redigera

Dela via


NumberFormatInfo Class

Definition

Provides culture-specific information for formatting and parsing numeric values.

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
Inheritance
NumberFormatInfo
Attributes
Implements

Examples

The following example shows how to retrieve a NumberFormatInfo object for a corresponding CultureInfo object, and use the retrieved object to query number formatting information for the particular culture.

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 '$'

Remarks

For more information about this API, see Supplemental API remarks for NumberFormatInfo.

Constructors

NumberFormatInfo()

Initializes a new writable instance of the NumberFormatInfo class that is culture-independent (invariant).

Properties

CurrencyDecimalDigits

Gets or sets the number of decimal places to use in currency values.

CurrencyDecimalSeparator

Gets or sets the string to use as the decimal separator in currency values.

CurrencyGroupSeparator

Gets or sets the string that separates groups of digits to the left of the decimal in currency values.

CurrencyGroupSizes

Gets or sets the number of digits in each group to the left of the decimal in currency values.

CurrencyNegativePattern

Gets or sets the format pattern for negative currency values.

CurrencyPositivePattern

Gets or sets the format pattern for positive currency values.

CurrencySymbol

Gets or sets the string to use as the currency symbol.

CurrentInfo

Gets a read-only NumberFormatInfo that formats values based on the current culture.

DigitSubstitution

Gets or sets a value that specifies how the graphical user interface displays the shape of a digit.

InvariantInfo

Gets a read-only NumberFormatInfo object that is culture-independent (invariant).

IsReadOnly

Gets a value that indicates whether this NumberFormatInfo object is read-only.

NaNSymbol

Gets or sets the string that represents the IEEE NaN (not a number) value.

NativeDigits

Gets or sets a string array of native digits equivalent to the Western digits 0 through 9.

NegativeInfinitySymbol

Gets or sets the string that represents negative infinity.

NegativeSign

Gets or sets the string that denotes that the associated number is negative.

NumberDecimalDigits

Gets or sets the number of decimal places to use in numeric values.

NumberDecimalSeparator

Gets or sets the string to use as the decimal separator in numeric values.

NumberGroupSeparator

Gets or sets the string that separates groups of digits to the left of the decimal in numeric values.

NumberGroupSizes

Gets or sets the number of digits in each group to the left of the decimal in numeric values.

NumberNegativePattern

Gets or sets the format pattern for negative numeric values.

PercentDecimalDigits

Gets or sets the number of decimal places to use in percent values.

PercentDecimalSeparator

Gets or sets the string to use as the decimal separator in percent values.

PercentGroupSeparator

Gets or sets the string that separates groups of digits to the left of the decimal in percent values.

PercentGroupSizes

Gets or sets the number of digits in each group to the left of the decimal in percent values.

PercentNegativePattern

Gets or sets the format pattern for negative percent values.

PercentPositivePattern

Gets or sets the format pattern for positive percent values.

PercentSymbol

Gets or sets the string to use as the percent symbol.

PerMilleSymbol

Gets or sets the string to use as the per mille symbol.

PositiveInfinitySymbol

Gets or sets the string that represents positive infinity.

PositiveSign

Gets or sets the string that denotes that the associated number is positive.

Methods

Clone()

Creates a shallow copy of the NumberFormatInfo object.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetFormat(Type)

Gets an object of the specified type that provides a number formatting service.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInstance(IFormatProvider)

Gets the NumberFormatInfo associated with the specified IFormatProvider.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ReadOnly(NumberFormatInfo)

Returns a read-only NumberFormatInfo wrapper.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to

See also