NumberFormatInfo.CurrencyGroupSizes 属性

定义

获取或设置货币值中小数点左边每一组的位数。

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[]

货币值中小数点左边每一组的位数。 InvariantInfo 的默认值是一个一维数组,该数组只包含一个设置为 3 的元素。

例外

该属性设置为 null

设置了该属性,但数组包含一个小于 0 或大于 9 的项。

- 或 -

设置了该属性,但数组包含一个设置为 0 的项(最后一项除外)。

设置了该属性,但 NumberFormatInfo 对象为只读。

示例

以下示例演示更改 CurrencyGroupSizes 属性的效果。

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”标准格式字符串一起使用,以定义整型组中出现的位数。 有关详细信息,请参阅标准数值格式字符串。 一维数组中的每个元素必须是 1 到 9 的整数。 最后一个元素可以为 0。

数组的第一个元素定义 紧邻 左侧的最小有效数字组中的 CurrencyDecimalSeparator元素数。 每个后续元素都引用上一组左侧的下一组重要数字。 如果数组的最后一个元素不是 0,则根据数组的最后一个元素对剩余数字进行分组。 如果最后一个元素为 0,则不会对剩余数字进行分组。

例如,如果数组包含 { 3, 4, 5 },则数字分组类似于“$55,55555,55555,55555,4444,333.00”。 如果数组包含 { 3, 4, 0 },则数字分组类似于“$555555555555555,4444,333.00”。

适用于

另请参阅