Sign in

NumberFormatInfo Class

Overview

The NumberFormatInfo class defines how numeric values are formatted and displayed, depending on culture-specific settings such as decimal separators, group separators, and currency symbols.

Properties
Methods
Examples

Properties

PropertyTypeDescription
CurrencyDecimalDigitsintNumber of decimal places to use in currency values.
CurrencyDecimalSeparatorstringString to use as the decimal separator in currency values.
CurrencyGroupSeparatorstringString to use as the group separator in currency values.
CurrencySymbolstringSymbol used to denote currency.
NumberDecimalDigitsintNumber of decimal places to use in numeric values.
NumberDecimalSeparatorstringString to use as the decimal separator in numeric values.
NumberGroupSeparatorstringString to use as the group separator in numeric values.
PercentDecimalDigitsintNumber of decimal places to use in percent values.
PercentSymbolstringSymbol used to denote percent.
PositiveSignstringString that denotes a positive sign.
NegativeSignstringString that denotes a negative sign.

Methods

MethodSignatureDescription
Cloneobject Clone()Creates a shallow copy of the current NumberFormatInfo object.
GetInstancestatic NumberFormatInfo GetInstance(IFormatProvider provider)Returns the NumberFormatInfo associated with the specified provider.
ReadOnlystatic NumberFormatInfo ReadOnly(NumberFormatInfo nfi)Returns a read-only wrapper for the specified NumberFormatInfo.

Example

Format a number using custom NumberFormatInfo settings:

using System;
using System.Globalization;

class Program
{
    static void Main()
    {
        var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
        nfi.CurrencySymbol = "€";
        nfi.NumberDecimalSeparator = ",";
        nfi.NumberGroupSeparator = ".";

        decimal value = 1234567.89m;
        Console.WriteLine(value.ToString("N", nfi));   // 1.234.567,89
        Console.WriteLine(value.ToString("C", nfi));   // €1.234.567,89
    }
}

Remarks

NumberFormatInfo is culture-sensitive. Use CultureInfo to obtain standard formats for a specific culture, or clone and modify a NumberFormatInfo instance for custom formatting.