System.Globalization.NumberFormatInfo.NumberGroupSizes Property

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

Syntax

public int[] NumberGroupSizes { get; set; }

Value

A int array containing elements that define the number of digits in each group in numeric values.

Exceptions

TypeReason
ArgumentNullExceptionThe array specified for a set operation is a null reference.
ArgumentOutOfRangeExceptionOne of the elements in the array specified for a set operation is not between 0 and 9.
InvalidOperationExceptionThe current instance is read-only and a set operation was attempted.

Remarks

The value of the NumberFormatInfo.NumberGroupSizes property affects the result of number values that are formatted by using the "N" standard numeric format string. If a custom numeric format string or other standard numeric format strings are used, the value of the NumberFormatInfo.NumberGroupSizes property is ignored.

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 are grouped similar to "55,55555,55555,55555,4444,333.00". If the array contains { 3, 4, 0 }, the digits are grouped similar to "55555555555555555,4444,333.00".

Example

The following example demonstrates the effects of different NumberFormatInfo.NumberGroupSizes property values.

C# Example

using System;
using System.Globalization;
class Test {
 public static void Main() {
 NumberFormatInfo nfi = new NumberFormatInfo();
 
 decimal data = 9999999994444333221.00m;
 nfi.NumberGroupSizes = new int[] {1,2,3,4,0};
 Console.WriteLine("{0}",data.ToString("N",nfi));

 data = 123456789123456.78m;
 nfi.NumberGroupSizes = new int[] {3};
 Console.WriteLine("{0}",data.ToString("N",nfi));

 nfi.NumberGroupSizes = new int[] {3,0};
 Console.WriteLine("{0}",data.ToString("N",nfi));
 }
}
   

The output is

999999999,4444,333,22,1.00
123,456,789,123,456.78
123456789123,456.78

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0