A int array containing elements that define the number of digits in each group in currency values.
Type Reason ArgumentNullException The array specified for a set operation is a null reference. ArgumentOutOfRangeException One of the elements in the array specified for a set operation is not between 0 and 9. InvalidOperationException The current instance is read-only and a set operation was attempted. ArgumentException One of the elements in the array specified for a set operation is not between 0 and 9.
-or-
The array contains an element, other than the last element, that is set to 0.
The NumberFormatInfo.CurrencyGroupSizes property is used with the "C" standard format string to define the number of digits that appear in integral groups. For more information, see Standard Numeric Format Strings. 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 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".
The following example demonstrates the effects of different NumberFormatInfo.CurrencyGroupSizes property values.
C# Example
using System; using System.Globalization; class Test { public static void Main() { NumberFormatInfo nfi = new NumberFormatInfo(); decimal myMoney = 9999999994444333221.00m; nfi.CurrencyGroupSizes = new int[] {1,2,3,4,0}; Console.WriteLine("{0}",myMoney.ToString("C",nfi)); myMoney = 123456789123456.78m; nfi.CurrencyGroupSizes = new int[] {3}; Console.WriteLine("{0}",myMoney.ToString("C",nfi)); nfi.CurrencyGroupSizes = new int[] {3,0}; Console.WriteLine("{0}",myMoney.ToString("C",nfi)); } }
The output is
$999999999,4444,333,22,1.00