NumberFormatInfo.CurrencyGroupSizes 属性

定义

获取或设置货币值中小数点左边每一组的位数。Gets or sets the number of digits in each group to the left of the decimal in currency values.

public:
 property cli::array <int> ^ CurrencyGroupSizes { cli::array <int> ^ get(); void set(cli::array <int> ^ value); };
public int[] CurrencyGroupSizes { get; set; }
member this.CurrencyGroupSizes : int[] with get, set
Public Property CurrencyGroupSizes As Integer()

属性值

Int32[]

货币值中小数点左边每一组的位数。The number of digits in each group to the left of the decimal in currency values. InvariantInfo 的默认值是一个一维数组,该数组只包含一个设置为 3 的元素。The default for InvariantInfo is a one-dimensional array with only one element, which is set to 3.

异常

该属性设置为 nullThe property is being set to null.

设置了该属性,但数组包含一个小于 0 或大于 9 的项。The property is being set and the array contains an entry that is less than 0 or greater than 9.

- 或 --or-

设置了该属性,但数组包含一个设置为 0 的项(最后一项除外)。The property is being set and the array contains an entry, other than the last entry, that is set to 0.

设置了该属性,但 NumberFormatInfo 对象为只读。The property is being set and the NumberFormatInfo object is read-only.

示例

下面的示例演示更改CurrencyGroupSizes属性的效果。The following example demonstrates the effect of changing the CurrencyGroupSizes property.

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   NumberFormatInfo^ nfi = MyCI->NumberFormat;
   
   // Displays a value with the default separator (S".").
   Int64 myInt = 123456789012345;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
   
   // Displays the same value with different groupings.
   array<Int32>^mySizes1 = {2,3,4};
   array<Int32>^mySizes2 = {2,3,0};
   nfi->CurrencyGroupSizes = mySizes1;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
   nfi->CurrencyGroupSizes = mySizes2;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
}

/* 
This code produces the following output.

$123, 456, 789, 012, 345.00
$12, 3456, 7890, 123, 45.00
$1234567890, 123, 45.00
*/
using System;
using System.Globalization;

class NumberFormatInfoSample {

   public static void Main() {

      // Gets a NumberFormatInfo associated with the en-US culture.
      NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;

      // Displays a value with the default separator (".").
      Int64 myInt = 123456789012345;
      Console.WriteLine( myInt.ToString( "C", nfi ) );

      // Displays the same value with different groupings.
      int[] mySizes1 = {2,3,4};
      int[] mySizes2 = {2,3,0};
      nfi.CurrencyGroupSizes = mySizes1;
      Console.WriteLine( myInt.ToString( "C", nfi ) );
      nfi.CurrencyGroupSizes = mySizes2;
      Console.WriteLine( myInt.ToString( "C", nfi ) );

   }
}


/* 
This code produces the following output.

$123,456,789,012,345.00
$12,3456,7890,123,45.00
$1234567890,123,45.00
*/
   
Imports System.Globalization

Class NumberFormatInfoSample
   
   
   Public Shared Sub Main()

      ' Gets a NumberFormatInfo associated with the en-US culture.
      Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat

      ' Displays a value with the default separator (".").
      Dim myInt As Int64 = 123456789012345
      Console.WriteLine(myInt.ToString("C", nfi))

      ' Displays the same value with different groupings.
      Dim mySizes1 As Integer() =  {2, 3, 4}
      Dim mySizes2 As Integer() =  {2, 3, 0}
      nfi.CurrencyGroupSizes = mySizes1
      Console.WriteLine(myInt.ToString("C", nfi))
      nfi.CurrencyGroupSizes = mySizes2
      Console.WriteLine(myInt.ToString("C", nfi))

   End Sub

End Class

 

'This code produces the following output.

'

'$123,456,789,012,345.00

'$12,3456,7890,123,45.00

'$1234567890,123,45.00


注解

CurrencyGroupSizes属性与 "C" 标准格式字符串一起使用,以定义在整数组中出现的位数。The 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. 一维数组中的每个元素都必须为1到9之间的整数。Every element in the one-dimensional array must be an integer from 1 through 9. 最后一个元素可以是0。The last element can be 0.

数组的第一个元素定义紧靠左侧CurrencyDecimalSeparator的最小有效位数组中的元素数目。The first element of the array defines the number of elements in the least significant group of digits immediately to the left of the CurrencyDecimalSeparator. 每个后续元素都是指上一组左侧的下一个重要数字组。Each subsequent element refers to the next significant group of digits to the left of the previous group. 如果数组的最后一个元素不是0,则将根据数组的最后一个元素对其余数字进行分组。If the last element of the array is not 0, the remaining digits are grouped based on the last element of the array. 如果最后一个元素是0,则不会对其余数字进行分组。If the last element is 0, the remaining digits are not grouped.

例如,如果数组包含 {3,4,5},则数字的分组类似于 "$ 55,55555,55555,55555,4444,333.00"。For example, if the array contains { 3, 4, 5 }, the digits are grouped similar to "$55,55555,55555,55555,4444,333.00". 如果数组包含 {3,4,0},则数字的分组类似于 "$ 55555555555555555,4444,333.00"。If the array contains { 3, 4, 0 }, the digits are grouped similar to "$55555555555555555,4444,333.00".

适用于

另请参阅