NumberFormatInfo Class

Definition

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

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

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

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also