System.Globalization.NumberFormatInfo Class

Assembly: Mscorlib.dll
Namespace: System.Globalization
Summary
Defines how numeric values are formatted and displayed, depending on the culture.
C# Syntax:
[Serializable]
public sealed class NumberFormatInfo : ICloneable, IFormatProvider
Thread Safety
This type is safe for multithreaded operations.
Remarks
This class contains information, such as currency, decimal separators, and other numeric symbols.

To create a NumberFormatInfo for a specific culture, create a CultureInfo for that culture and retrieve the CultureInfo.NumberFormat property. To create a NumberFormatInfo for the culture of the current thread, use the NumberFormatInfo.CurrentInfo property. To create a NumberFormatInfo for the invariant culture, use the NumberFormatInfo.InvariantInfo property for a read-only version, or use the NumberFormatInfo constructor for a writable version. It is not possible to create a NumberFormatInfo for a neutral culture.

The user might choose to override some of the values associated with the current culture of Windows through Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture. If the CultureInfo.UseUserOverride property is set to true, the properties of the CultureInfo.DateTimeFormat instance, the CultureInfo.NumberFormat instance, and the CultureInfo.TextInfo instance are also retrieved from the user settings. If the user settings are incompatible with the culture associated with the CultureInfo (for example, if the selected calendar is not one of the CultureInfo.OptionalCalendars), the results of the methods and the values of the properties are undefined.

Numeric values are formatted using standard or custom patterns stored in the properties of a NumberFormatInfo. To modify how a value is displayed, the NumberFormatInfo must be writable so custom patterns can be saved in its properties.

The following table lists the standard format characters for each standard pattern and the associated NumberFormatInfo property that can be set to modify the standard pattern.



Format Character Description and Associated Properties
c, C Currency format. NumberFormatInfo.CurrencyNegativePattern , NumberFormatInfo.CurrencyPositivePattern , NumberFormatInfo.CurrencySymbol , NumberFormatInfo.CurrencyGroupSizes , NumberFormatInfo.CurrencyGroupSeparator , NumberFormatInfo.CurrencyDecimalDigits , NumberFormatInfo.CurrencyDecimalSeparator .
d, D Decimal format.
e, E Scientific (exponential) format.
f, F Fixed-point format.
g, G General format.
n, N Number format. NumberFormatInfo.NumberNegativePattern , NumberFormatInfo.NumberGroupSizes , NumberFormatInfo.NumberGroupSeparator , NumberFormatInfo.NumberDecimalDigits , NumberFormatInfo.NumberDecimalSeparator .
r, R Roundtrip format, which ensures that numbers converted to strings will have the same value when they are converted back to numbers.
x, X Hexadecimal format.

A DateTimeFormatInfo or a NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures. For more information about the invariant culture, specific cultures, and neutral cultures, see the CultureInfo class.

This class implements the ICloneable interface to enable duplication of NumberFormatInfo objects. It also implements IFormatProvider to supply formatting information to applications.

See also:
System.Globalization Namespace | Decimal | CultureInfo | MSDN: formattingoverview

System.Globalization.NumberFormatInfo Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new writable instance of the NumberFormatInfo class that is culture-independent (invariant).
Public Properties
CurrencyDecimalDigits Read-write

Indicates the number of decimal places to use in currency values.
CurrencyDecimalSeparator Read-write

Gets or sets the string to use as the decimal separator in currency values.
CurrencyGroupSeparator Read-write

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

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

Gets or sets the format pattern for negative currency values.
CurrencyPositivePattern Read-write

Gets or sets the format pattern for positive currency values.
CurrencySymbol Read-write

Gets or sets the string to use as the currency symbol.
CurrentInfo Read-only

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

Gets the default read-only NumberFormatInfo that is culture-independent (invariant).
IsReadOnly Read-only

Gets a value indicating whether the NumberFormatInfo is read-only.
NaNSymbol Read-write

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

Gets or sets the string that represents negative infinity.
NegativeSign Read-write

Gets or sets the string that denotes that the associated number is negative.
NumberDecimalDigits Read-write

Gets or sets the number of decimal places to use in numeric values.
NumberDecimalSeparator Read-write

Gets or sets the string to use as the decimal separator in numeric values.
NumberGroupSeparator Read-write

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

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

Gets or sets the format pattern for negative numeric values.
PercentDecimalDigits Read-write

Gets or sets the number of decimal places to use in percent values.
PercentDecimalSeparator Read-write

Gets or sets the string to use as the decimal separator in percent values.
PercentGroupSeparator Read-write

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

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

Gets or sets the format pattern for negative percent values.
PercentPositivePattern Read-write

Gets or sets the format pattern for positive percent values.
PercentSymbol Read-write

Gets or sets the string to use as the percent symbol.
PerMilleSymbol Read-write

Gets or sets the string to use as the per mille symbol.
PositiveInfinitySymbol Read-write

Gets or sets the string that represents positive infinity.
PositiveSign Read-write

Gets or sets the string that denotes that the associated number is positive.
Public Methods
Clone Creates a shallow copy of the NumberFormatInfo.
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetFormat Gets an object of the specified type that provides a number formatting service.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetInstance Gets the NumberFormatInfo associated with the specified IFormatProvider.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ReadOnly Returns a read-only NumberFormatInfo wrapper.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Globalization.NumberFormatInfo Member Details

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

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public NumberFormatInfo();
Remarks
The properties of the new instance can be modified if you want user-defined formatting.

Return to top


Property: CurrencyDecimalDigits (read-write)
Summary
Indicates the number of decimal places to use in currency values.
C# Syntax:
public int CurrencyDecimalDigits {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 99.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.CurrencyPositivePattern | NumberFormatInfo.NumberDecimalDigits | NumberFormatInfo.PercentDecimalDigits

Return to top


Property: CurrencyDecimalSeparator (read-write)
Summary
Gets or sets the string to use as the decimal separator in currency values.
C# Syntax:
public string CurrencyDecimalSeparator {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
ArgumentException The property is being set to a value that is the same as NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
The initial value of this property is derived from the settings in Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. However, if any of the group separators ( NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator) is the same as any of the decimal separators ( NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator), parsing ambiguous strings produces unpredictable results. If you explicitly set any of the group separator properties in NumberFormatInfo to a value that is the same as any of the decimal separators or if you explicitly set any of the decimal separators to a value that is the same as any of the group separators, ArgumentException is thrown.
See also:
NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.CurrencyPositivePattern | NumberFormatInfo.NumberDecimalSeparator | NumberFormatInfo.PercentDecimalSeparator

Return to top


Property: CurrencyGroupSeparator (read-write)
Summary
Gets or sets the string that separates groups of digits to the left of the decimal in currency values.
C# Syntax:
public string CurrencyGroupSeparator {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
ArgumentException The property is being set to a value that is the same as NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
The initial value of this property is derived from the settings in Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. However, if any of the group separators ( NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator) is the same as any of the decimal separators ( NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator), parsing ambiguous strings produces unpredictable results. If you explicitly set any of the group separator properties in NumberFormatInfo to a value that is the same as any of the decimal separators or if you explicitly set any of the decimal separators to a value that is the same as any of the group separators, ArgumentException is thrown.
See also:
NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.CurrencyPositivePattern | NumberFormatInfo.NumberGroupSeparator | NumberFormatInfo.PercentGroupSeparator

Return to top


Property: CurrencyGroupSizes (read-write)
Summary
Gets or sets the number of digits in each group to the left of the decimal in currency values.
C# Syntax:
public int[] CurrencyGroupSizes {get; set;}
Exceptions
Exception Type Condition
ArgumentException The property is being set and the array contains an entry that is less than 0 or greater than 9.

-or-

The property is being set and the array contains an entry, other than the last entry, that is set to 0.

InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
Every element in the one-dimensional array must be an integer from 1 through 9. The last element can be 0.

The first element of the array defines the number of elements in the least significant group of digits immediately to the left of the NumberFormatInfo.CurrencyDecimalSeparator. Each subsequent element refers to the next significant group of digits to the left of the previous group. If the last element of the array is not 0, the remaining digits are grouped based on the last element of the array. If the last element is 0, the remaining digits are not grouped.

For example, if the array contains { 3, 4, 5 }, the digits will be grouped similar to "$55,55555,55555,55555,4444,333.00". If the array contains { 3, 4, 0 }, the digits will be grouped similar to "$55555555555555555,4444,333.00".

See also:
NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.CurrencyPositivePattern | NumberFormatInfo.NumberGroupSizes | NumberFormatInfo.PercentGroupSizes

Return to top


Property: CurrencyNegativePattern (read-write)
Summary
Gets or sets the format pattern for negative currency values.
C# Syntax:
public int CurrencyNegativePattern {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 15.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
This property can have one of the values in the following table. The symbol "$" is the NumberFormatInfo.CurrencySymbol, the symbol "-" is the NumberFormatInfo.NegativeSign, and n is a number.

Value Associated Pattern
0 ($n)
1 -$n
2 $-n
3 $n-
4 (n$)
5 -n$
6 n-$
7 n$-
8 -n $
9 -$ n
10 n $-
11 $ n-
12 $ -n
13 n- $
14 ($ n)
15 (n $)
See also:
NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.CurrencyPositivePattern | NumberFormatInfo.NumberNegativePattern | NumberFormatInfo.PercentNegativePattern

Return to top


Property: CurrencyPositivePattern (read-write)
Summary
Gets or sets the format pattern for positive currency values.
C# Syntax:
public int CurrencyPositivePattern {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 3.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
This property can have one of the values in the following table. The symbol "$" is the NumberFormatInfo.CurrencySymbol and n is a number.

Value Associated Pattern
0 $n
1 n$
2 $ n
3 n $
See also:
NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.PercentPositivePattern

Return to top


Property: CurrencySymbol (read-write)
Summary
Gets or sets the string to use as the currency symbol.
C# Syntax:
public string CurrencySymbol {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.CurrencyPositivePattern | NumberFormatInfo.NaNSymbol | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PerMilleSymbol

Return to top


Property: CurrentInfo (read-only)
Summary
Gets a read-only NumberFormatInfo that formats values based on the current culture.
C# Syntax:
public static NumberFormatInfo CurrentInfo {get;}
See also:
CultureInfo

Return to top


Property: InvariantInfo (read-only)
Summary
Gets the default read-only NumberFormatInfo that is culture-independent (invariant).
C# Syntax:
public static NumberFormatInfo InvariantInfo {get;}
Remarks
This property does not change, regardless of the current culture.
Example
The following code example displays the default property values of the NumberFormatInfo.InvariantInfo.
using System;
using System.Globalization;
using System.Text;

class SamplesNumberFormatInfo  {

   public static void Main()  {

      // Gets the InvariantInfo.
      NumberFormatInfo myInv = NumberFormatInfo.InvariantInfo;

      // Gets a UnicodeEncoding to display the Unicode value of symbols.
      UnicodeEncoding myUE = new UnicodeEncoding( true, false );
      byte[] myCodes;

      // Displays the default values for each of the properties.
      Console.WriteLine( "InvariantInfo:\nNote: Symbols may not display correctly on the console,\ntherefore, Unicode values are included." );
      Console.WriteLine( "\tCurrencyDecimalDigits\t\t{0}", myInv.CurrencyDecimalDigits );
      Console.WriteLine( "\tCurrencyDecimalSeparator\t{0}", myInv.CurrencyDecimalSeparator );
      Console.WriteLine( "\tCurrencyGroupSeparator\t\t{0}", myInv.CurrencyGroupSeparator );
      Console.WriteLine( "\tCurrencyGroupSizes\t\t{0}", myInv.CurrencyGroupSizes[0] );
      Console.WriteLine( "\tCurrencyNegativePattern\t\t{0}", myInv.CurrencyNegativePattern );
      Console.WriteLine( "\tCurrencyPositivePattern\t\t{0}", myInv.CurrencyPositivePattern );
      myCodes = myUE.GetBytes( myInv.CurrencySymbol );
      Console.WriteLine( "\tCurrencySymbol\t\t\t{0}\t(U+{1:x2}{2:x2})", myInv.CurrencySymbol, myCodes[0], myCodes[1] );
      Console.WriteLine( "\tNaNSymbol\t\t\t{0}", myInv.NaNSymbol );
      Console.WriteLine( "\tNegativeInfinitySymbol\t\t{0}", myInv.NegativeInfinitySymbol );
      Console.WriteLine( "\tNegativeSign\t\t\t{0}", myInv.NegativeSign );
      Console.WriteLine( "\tNumberDecimalDigits\t\t{0}", myInv.NumberDecimalDigits );
      Console.WriteLine( "\tNumberDecimalSeparator\t\t{0}", myInv.NumberDecimalSeparator );
      Console.WriteLine( "\tNumberGroupSeparator\t\t{0}", myInv.NumberGroupSeparator );
      Console.WriteLine( "\tNumberGroupSizes\t\t{0}", myInv.NumberGroupSizes[0] );
      Console.WriteLine( "\tNumberNegativePattern\t\t{0}", myInv.NumberNegativePattern );
      Console.WriteLine( "\tPercentDecimalDigits\t\t{0}", myInv.PercentDecimalDigits );
      Console.WriteLine( "\tPercentDecimalSeparator\t\t{0}", myInv.PercentDecimalSeparator );
      Console.WriteLine( "\tPercentGroupSeparator\t\t{0}", myInv.PercentGroupSeparator );
      Console.WriteLine( "\tPercentGroupSizes\t\t{0}", myInv.PercentGroupSizes[0] );
      Console.WriteLine( "\tPercentNegativePattern\t\t{0}", myInv.PercentNegativePattern );
      Console.WriteLine( "\tPercentPositivePattern\t\t{0}", myInv.PercentPositivePattern );
      myCodes = myUE.GetBytes( myInv.PercentSymbol );
      Console.WriteLine( "\tPercentSymbol\t\t\t{0}\t(U+{1:x2}{2:x2})", myInv.PercentSymbol, myCodes[0], myCodes[1] );
      myCodes = myUE.GetBytes( myInv.PerMilleSymbol );
      Console.WriteLine( "\tPerMilleSymbol\t\t\t{0}\t(U+{1:x2}{2:x2})", myInv.PerMilleSymbol, myCodes[0], myCodes[1] );
      Console.WriteLine( "\tPositiveInfinitySymbol\t\t{0}", myInv.PositiveInfinitySymbol );
      Console.WriteLine( "\tPositiveSign\t\t\t{0}", myInv.PositiveSign );

   }
}


/*

This code produces the following output.

InvariantInfo:
Note: Symbols may not display correctly on the console,
therefore, Unicode values are included.
        CurrencyDecimalDigits           2
        CurrencyDecimalSeparator        .
        CurrencyGroupSeparator          ,
        CurrencyGroupSizes              3
        CurrencyNegativePattern         0
        CurrencyPositivePattern         0
        CurrencySymbol                         (U+00a4)
        NaNSymbol                       NaN
        NegativeInfinitySymbol          -Infinity
        NegativeSign                    -
        NumberDecimalDigits             2
        NumberDecimalSeparator          .
        NumberGroupSeparator            ,
        NumberGroupSizes                3
        NumberNegativePattern           1
        PercentDecimalDigits            2
        PercentDecimalSeparator         .
        PercentGroupSeparator           ,
        PercentGroupSizes               3
        PercentNegativePattern          0
        PercentPositivePattern          0
        PercentSymbol                   %       (U+0025)
        PerMilleSymbol                  %       (U+2030)
        PositiveInfinitySymbol          Infinity
        PositiveSign                    +

*/


    

Return to top


Property: IsReadOnly (read-only)
Summary
Gets a value indicating whether the NumberFormatInfo is read-only.
C# Syntax:
public bool IsReadOnly {get;}
Remarks
Attempting to perform an assignment to a property of a read-only NumberFormatInfo causes an InvalidOperationException.
See also:
NumberFormatInfo.ReadOnly

Return to top


Property: NaNSymbol (read-write)
Summary
Gets or sets the string that represents the IEEE NaN (not a number) value.
C# Syntax:
public string NaNSymbol {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
For more information on NaN values, see Double or Single.
See also:
NumberFormatInfo.NumberDecimalDigits | NumberFormatInfo.NumberDecimalSeparator | NumberFormatInfo.NumberGroupSeparator | NumberFormatInfo.NumberGroupSizes | NumberFormatInfo.NumberNegativePattern | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PerMilleSymbol

Return to top


Property: NegativeInfinitySymbol (read-write)
Summary
Gets or sets the string that represents negative infinity.
C# Syntax:
public string NegativeInfinitySymbol {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
For more information on negative infinity, see Double or Single.
See also:
NumberFormatInfo.PositiveInfinitySymbol

Return to top


Property: NegativeSign (read-write)
Summary
Gets or sets the string that denotes that the associated number is negative.
C# Syntax:
public string NegativeSign {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.PositiveSign

Return to top


Property: NumberDecimalDigits (read-write)
Summary
Gets or sets the number of decimal places to use in numeric values.
C# Syntax:
public int NumberDecimalDigits {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 99.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.NumberDecimalSeparator | NumberFormatInfo.NumberGroupSeparator | NumberFormatInfo.NumberGroupSizes | NumberFormatInfo.NaNSymbol | NumberFormatInfo.NumberNegativePattern | NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.PercentDecimalDigits

Return to top


Property: NumberDecimalSeparator (read-write)
Summary
Gets or sets the string to use as the decimal separator in numeric values.
C# Syntax:
public string NumberDecimalSeparator {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
ArgumentException The property is being set to a value that is the same as NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
The initial value of this property is derived from the settings in Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. However, if any of the group separators ( NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator) is the same as any of the decimal separators ( NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator), parsing ambiguous strings produces unpredictable results. If you explicitly set any of the group separator properties in NumberFormatInfo to a value that is the same as any of the decimal separators or if you explicitly set any of the decimal separators to a value that is the same as any of the group separators, ArgumentException is thrown.
See also:
NumberFormatInfo.NumberDecimalDigits | NumberFormatInfo.NumberGroupSeparator | NumberFormatInfo.NumberGroupSizes | NumberFormatInfo.NaNSymbol | NumberFormatInfo.NumberNegativePattern | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.PercentDecimalSeparator

Return to top


Property: NumberGroupSeparator (read-write)
Summary
Gets or sets the string that separates groups of digits to the left of the decimal in numeric values.
C# Syntax:
public string NumberGroupSeparator {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
ArgumentException The property is being set to a value that is the same as NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
The initial value of this property is derived from the settings in Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. However, if any of the group separators ( NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator) is the same as any of the decimal separators ( NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator), parsing ambiguous strings produces unpredictable results. If you explicitly set any of the group separator properties in NumberFormatInfo to a value that is the same as any of the decimal separators or if you explicitly set any of the decimal separators to a value that is the same as any of the group separators, ArgumentException is thrown.
See also:
NumberFormatInfo.NumberDecimalDigits | NumberFormatInfo.NumberDecimalSeparator | NumberFormatInfo.NumberGroupSizes | NumberFormatInfo.NaNSymbol | NumberFormatInfo.NumberNegativePattern | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.PercentGroupSeparator

Return to top


Property: NumberGroupSizes (read-write)
Summary
Gets or sets the number of digits in each group to the left of the decimal in numeric values.
C# Syntax:
public int[] NumberGroupSizes {get; set;}
Exceptions
Exception Type Condition
ArgumentException The property is being set and the array contains an entry that is less than 0 or greater than 9.

-or-

The property is being set and the array contains an entry, other than the last entry, that is set to 0.

InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
Every element in the one-dimensional array must be an integer from 1 through 9. The last element can be 0.

The first element of the array defines the number of elements in the least significant group of digits immediately to the left of the NumberFormatInfo.NumberDecimalSeparator. Each subsequent element refers to the next significant group of digits to the left of the previous group. If the last element of the array is not 0, the remaining digits are grouped based on the last element of the array. If the last element is 0, the remaining digits are not grouped.

For example, if the array contains { 3, 4, 5 }, the digits will be grouped similar to "55,55555,55555,55555,4444,333.00". If the array contains { 3, 4, 0 }, the digits will be grouped similar to "55555555555555555,4444,333.00".

Example
The following code example prints a value using different NumberFormatInfo.NumberGroupSizes arrays.
 using System;
 using System.Globalization;
 class SamplesNumberFormatInfo  {
 
    public static void Main()  {
 
       // Creates a new NumberFormatinfo.
       NumberFormatInfo myNfi = new NumberFormatInfo();
 
       // Takes a long value.
       Int64 myInt = 123456789012345;
 
       // Displays the value with default formatting.
       Console.WriteLine( "Default  \t\t:\t{0}", myInt.ToString(myNfi) );
 
       // Displays the value with three elements in the GroupSize array.
       myNfi.NumberGroupSizes = new int[]  { 2, 3, 4 };
       Console.WriteLine( "Grouping ( {0} )\t:\t{1}",
          PrintArraySet( myNfi.NumberGroupSizes ), myInt.ToString(myNfi) );
 
       // Displays the value with zero as the last element in the GroupSize array.
       myNfi.NumberGroupSizes = new int[]  { 2, 4, 0 };
       Console.WriteLine( "Grouping ( {0} )\t:\t{1}",
          PrintArraySet( myNfi.NumberGroupSizes ), myInt.ToString(myNfi) );
    }
 
    public static string PrintArraySet( int[] myArr )  {
       string myStr = null;
       myStr = myArr[0].ToString();
       for ( int i = 1; i < myArr.Length; i++ )
          myStr += ", " + myArr[i].ToString();
       return( myStr );
    }
 }
 /*
 This code produces the following output. 
 
 Default                 :       123,456,789,012,345.00
 Grouping ( 2, 3, 4 )    :       12,3456,7890,123,45.00
 Grouping ( 2, 4, 0 )    :       123456789,0123,45.00
 */

    
See also:
NumberFormatInfo.NumberDecimalDigits | NumberFormatInfo.NumberDecimalSeparator | NumberFormatInfo.NumberGroupSeparator | NumberFormatInfo.NaNSymbol | NumberFormatInfo.NumberNegativePattern | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.PercentGroupSizes

Return to top


Property: NumberNegativePattern (read-write)
Summary
Gets or sets the format pattern for negative numeric values.
C# Syntax:
public int NumberNegativePattern {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 4.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
This property can have one of the values in the following table. The symbol "-" is the NumberFormatInfo.NegativeSign and n is a number.

Value Associated Pattern
0 (n)
1 -n
2 - n
3 n-
4 n -
Example
The following code example prints a value using different NumberFormatInfo.NumberNegativePattern patterns.
 using System;
 using System.Globalization;
 class SamplesNumberFormatInfo  {
 
    public static void Main()  {
 
       // Creates a new NumberFormatinfo.
       NumberFormatInfo myNfi = new NumberFormatInfo();

       // Takes a negative value.
       Int64 myInt = -1234;

       // Displays the value with default formatting.
       Console.WriteLine( "Default  \t:\t{0}", myInt.ToString( "N", myNfi ) );

       // Displays the value with other patterns.
       for ( int i = 0; i <= 4; i++ )  {
          myNfi.NumberNegativePattern = i;
          Console.WriteLine( "Pattern {0}\t:\t{1}", myNfi.NumberNegativePattern, myInt.ToString( "N", myNfi ) );
       }
    }
 }
 /*
 This code produces the following output.
 
 Default         :       (1,234.00)
 Pattern 0       :       (1,234.00)
 Pattern 1       :       -1,234.00
 Pattern 2       :       - 1,234.00
 Pattern 3       :       1,234.00-
 Pattern 4       :       1,234.00 -
*/

    
See also:
NumberFormatInfo.NumberDecimalDigits | NumberFormatInfo.NumberDecimalSeparator | NumberFormatInfo.NumberGroupSeparator | NumberFormatInfo.NumberGroupSizes | NumberFormatInfo.NaNSymbol | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.PercentNegativePattern

Return to top


Property: PercentDecimalDigits (read-write)
Summary
Gets or sets the number of decimal places to use in percent values.
C# Syntax:
public int PercentDecimalDigits {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 99.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.PercentDecimalSeparator | NumberFormatInfo.PercentGroupSeparator | NumberFormatInfo.PercentGroupSizes | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PercentNegativePattern | NumberFormatInfo.PercentPositivePattern | NumberFormatInfo.CurrencyDecimalDigits | NumberFormatInfo.NumberDecimalDigits

Return to top


Property: PercentDecimalSeparator (read-write)
Summary
Gets or sets the string to use as the decimal separator in percent values.
C# Syntax:
public string PercentDecimalSeparator {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
ArgumentException The property is being set to a value that is the same as NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
If any of the group separators ( NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator) is the same as any of the decimal separators ( NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator), parsing ambiguous strings produces unpredictable results. If you explicitly set any of the group separator properties in NumberFormatInfo to a value that is the same as any of the decimal separators or if you explicitly set any of the decimal separators to a value that is the same as any of the group separators, ArgumentException is thrown.
See also:
NumberFormatInfo.PercentDecimalDigits | NumberFormatInfo.PercentGroupSeparator | NumberFormatInfo.PercentGroupSizes | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PercentNegativePattern | NumberFormatInfo.PercentPositivePattern | NumberFormatInfo.CurrencyDecimalSeparator | NumberFormatInfo.NumberDecimalSeparator

Return to top


Property: PercentGroupSeparator (read-write)
Summary
Gets or sets the string that separates groups of digits to the left of the decimal in percent values.
C# Syntax:
public string PercentGroupSeparator {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
ArgumentException The property is being set to a value that is the same as NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
If any of the group separators ( NumberFormatInfo.NumberGroupSeparator, NumberFormatInfo.CurrencyGroupSeparator, or NumberFormatInfo.PercentGroupSeparator) is the same as any of the decimal separators ( NumberFormatInfo.NumberDecimalSeparator, NumberFormatInfo.CurrencyDecimalSeparator, or NumberFormatInfo.PercentDecimalSeparator), parsing ambiguous strings produces unpredictable results. If you explicitly set any of the group separator properties in NumberFormatInfo to a value that is the same as any of the decimal separators or if you explicitly set any of the decimal separators to a value that is the same as any of the group separators, ArgumentException is thrown.
See also:
NumberFormatInfo.PercentDecimalDigits | NumberFormatInfo.PercentDecimalSeparator | NumberFormatInfo.PercentGroupSizes | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PercentNegativePattern | NumberFormatInfo.PercentPositivePattern | NumberFormatInfo.CurrencyGroupSeparator | NumberFormatInfo.NumberGroupSeparator

Return to top


Property: PercentGroupSizes (read-write)
Summary
Gets or sets the number of digits in each group to the left of the decimal in percent values.
C# Syntax:
public int[] PercentGroupSizes {get; set;}
Exceptions
Exception Type Condition
ArgumentException The property is being set and the array contains an entry that is less than 0 or greater than 9.

-or-

The property is being set and the array contains an entry, other than the last entry, that is set to 0.

InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
Every element in the one-dimensional array must be an integer from 1 through 9. The last element can be 0.

The first element of the array defines the number of elements in the least significant group of digits immediately to the left of the NumberFormatInfo.PercentDecimalSeparator. Each subsequent element refers to the next significant group of digits to the left of the previous group. If the last element of the array is not 0, the remaining digits are grouped based on the last element of the array. If the last element is 0, the remaining digits are not grouped.

For example, if the array contains { 3, 4, 5 }, the digits will be grouped similar to "55,55555,55555,55555,4444,333.00%". If the array contains { 3, 4, 0 }, the digits will be grouped similar to "55555555555555555,4444,333.00%".

See also:
NumberFormatInfo.PercentDecimalDigits | NumberFormatInfo.PercentDecimalSeparator | NumberFormatInfo.PercentGroupSeparator | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PercentNegativePattern | NumberFormatInfo.PercentPositivePattern | NumberFormatInfo.CurrencyGroupSizes | NumberFormatInfo.NumberGroupSizes

Return to top


Property: PercentNegativePattern (read-write)
Summary
Gets or sets the format pattern for negative percent values.
C# Syntax:
public int PercentNegativePattern {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 2.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
This property can have one of the values in the following table. The symbol "%" is the NumberFormatInfo.PercentSymbol, the symbol "-" is the NumberFormatInfo.NegativeSign, and n is a number.

Value Associated Pattern
0 -n %
1 -n%
2 -%n
See also:
NumberFormatInfo.PercentDecimalDigits | NumberFormatInfo.PercentDecimalSeparator | NumberFormatInfo.PercentGroupSeparator | NumberFormatInfo.PercentGroupSizes | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PercentPositivePattern | NumberFormatInfo.CurrencyNegativePattern | NumberFormatInfo.NumberNegativePattern

Return to top


Property: PercentPositivePattern (read-write)
Summary
Gets or sets the format pattern for positive percent values.
C# Syntax:
public int PercentPositivePattern {get; set;}
Exceptions
Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 2.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
This property can have one of the values in the following table. The symbol "%" is the NumberFormatInfo.PercentSymbol and n is a number.

Value Associated Pattern
0 n %
1 n%
2 %n
See also:
NumberFormatInfo.PercentDecimalDigits | NumberFormatInfo.PercentDecimalSeparator | NumberFormatInfo.PercentGroupSeparator | NumberFormatInfo.PercentGroupSizes | NumberFormatInfo.PercentSymbol | NumberFormatInfo.PercentNegativePattern | NumberFormatInfo.CurrencyPositivePattern

Return to top


Property: PercentSymbol (read-write)
Summary
Gets or sets the string to use as the percent symbol.
C# Syntax:
public string PercentSymbol {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.PercentDecimalDigits | NumberFormatInfo.PercentDecimalSeparator | NumberFormatInfo.PercentGroupSeparator | NumberFormatInfo.PercentGroupSizes | NumberFormatInfo.PercentNegativePattern | NumberFormatInfo.PercentPositivePattern | NumberFormatInfo.CurrencySymbol | NumberFormatInfo.NaNSymbol | NumberFormatInfo.PerMilleSymbol

Return to top


Property: PerMilleSymbol (read-write)
Summary
Gets or sets the string to use as the per mille symbol.
C# Syntax:
public string PerMilleSymbol {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
See also:
NumberFormatInfo.CurrencySymbol | NumberFormatInfo.NaNSymbol | NumberFormatInfo.PercentSymbol

Return to top


Property: PositiveInfinitySymbol (read-write)
Summary
Gets or sets the string that represents positive infinity.
C# Syntax:
public string PositiveInfinitySymbol {get; set;}
Exceptions
Exception Type Condition
ArgumentNullException The property is being set to null.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
For more information on positive infinity, see Double or Single.
See also:
NumberFormatInfo.NegativeInfinitySymbol

Return to top


Property: PositiveSign (read-write)
Summary
Gets or sets the string that denotes that the associated number is positive.
C# Syntax:
public string PositiveSign {get; set;}
Exceptions
Exception Type Condition
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.
Remarks
This property is used only for parsing numeric strings, not for formatting.
See also:
NumberFormatInfo.NegativeSign

Return to top


Method: Clone()
Summary
Creates a shallow copy of the NumberFormatInfo.
C# Syntax:
public object Clone();
Return Value:
A new NumberFormatInfo copied from the original NumberFormatInfo.
Implements:
ICloneable.Clone
Remarks
The clone is writable even if the original NumberFormatInfo is read-only; therefore, the properties of the clone can be modified with user-defined patterns.

A shallow copy of an object is a copy of the object only. If the object contains references to other objects, the shallow copy will not create copies of the referred objects. It will refer to the original objects instead. On the other hand, a deep copy of an object creates a copy of the object and a copy of everything directly or indirectly referenced by that object.

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~NumberFormatInfo();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetFormat(
   Type formatType
)
Summary
Gets an object of the specified type that provides a number formatting service.
C# Syntax:
public object GetFormat(
   Type formatType
);
Parameters:

formatType

The Type of the required formatting service.

Return Value:
The current NumberFormatInfo, if formatType is the same as the type of the current NumberFormatInfo; otherwise, null.
Implements:
IFormatProvider.GetFormat
Remarks
The Format(String, IFormatProvider) methods supported by the base data types invoke this method when the current NumberFormatInfo is passed as the IFormatProvider parameter. This method implements IFormatProvider.GetFormat.
See also:
IFormatProvider | DateTimeFormatInfo.GetFormat

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetInstance(
   IFormatProvider formatProvider
)
Summary
Gets the NumberFormatInfo associated with the specified IFormatProvider.
C# Syntax:
public static NumberFormatInfo GetInstance(
   IFormatProvider formatProvider
);
Parameters:

formatProvider

The IFormatProvider used to get the NumberFormatInfo.

-or-

null to get NumberFormatInfo.CurrentInfo.

The IFormatProvider used to get the NumberFormatInfo.

-or-

null to get NumberFormatInfo.CurrentInfo.

Return Value:
The NumberFormatInfo associated with the specified IFormatProvider.
Remarks
This method uses the IFormatProvider.GetFormat method of formatProvider using NumberFormatInfo as the Type parameter. If formatProvider is null or if IFormatProvider.GetFormat returns null, this method returns NumberFormatInfo.CurrentInfo.

You can get a NumberFormatInfo for a specific culture using one of the following methods:

A NumberFormatInfo can be created only for the invariant culture or for specific cultures, not for neutral cultures. For more information about the invariant culture, specific cultures, and neutral cultures, see the CultureInfo class.

See also:
IFormatProvider

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ReadOnly(
   NumberFormatInfo nfi
)
Summary
Returns a read-only NumberFormatInfo wrapper.
C# Syntax:
public static NumberFormatInfo ReadOnly(
   NumberFormatInfo nfi
);
Parameters:

nfi

The NumberFormatInfo to wrap.

Return Value:
A read-only NumberFormatInfo wrapper around nfi.
Exceptions
Exception Type Condition
ArgumentNullException nfi is null.
Remarks
This wrapper prevents any modifications to nfi.

Attempting to perform an assignment to a property of a read-only NumberFormatInfo causes an InvalidOperationException.

See also:
NumberFormatInfo.IsReadOnly

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.