A int array containing elements that define the number of digits in each group in percent 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.PercentGroupSizes property is used with the "P" 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.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 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.PercentGroupSizes property values.
C# Example
using System; using System.Globalization; class Test { public static void Main() { NumberFormatInfo nfi = new NumberFormatInfo(); decimal data = 9999999994444333221.00m; nfi.PercentGroupSizes = new int[] {1,2,3,4,0}; Console.WriteLine("{0}",data.ToString("P",nfi)); data = 123456789123456.78m; nfi.PercentGroupSizes = new int[] {3}; Console.WriteLine("{0}",data.ToString("P",nfi)); nfi.PercentGroupSizes = new int[] {3,0}; Console.WriteLine("{0}",data.ToString("P",nfi)); } }
The output is
99999999944,4433,322,10,0.00 %