NumberFormatInfo.PercentGroupSizes プロパティ

パーセント値で小数点の左にある各グループの数字の数を取得または設定します。

Public Property PercentGroupSizes As Integer ()
[C#]
public int[] PercentGroupSizes {get; set;}
[C++]
public: __property int get_PercentGroupSizes();public: __property void set_PercentGroupSizes(int __gc[]);
[JScript]
public function get PercentGroupSizes() : int[];
public function set PercentGroupSizes(int[]);

プロパティ値

パーセント値で小数点の左にある各グループの数字の数。 InvariantInfo の既定値は 1 つだけの要素を持つ 1 次元配列であり、その要素は 3 に設定されます。

例外

例外の種類 条件
ArgumentNullException プロパティが null 参照 (Visual Basic では Nothing) に設定されています。
ArgumentException プロパティが設定されており、配列に 0 よりも小さいか、9 よりも大きいエントリが格納されています。

または

プロパティが設定されており、配列で最後のエントリ以外のエントリが 0 に設定されています。

InvalidOperationException プロパティが設定されていますが、 NumberFormatInfo が読み取り専用です。

解説

1 次元配列のすべての要素は、1 ~ 9 の間の整数にする必要があります。最後の要素は 0 にできます。

配列の最初の要素は、 PercentDecimalSeparator のすぐ左にある、最も桁の小さい数字のグループの要素数を定義します。後続の各要素は、前のグループの左にある、次に桁の大きい数字のグループを参照します。配列の最後の要素が 0 ではない場合、残りの数字は配列の最後の要素に基づいてグループ化されます。最後の要素が 0 の場合、残りの数字はグループ化されません。

たとえば、配列が { 3, 4, 5 } を格納している場合、その数字は "$55,55555,55555,55555,4444,333.00%" のようにグループ化されます。配列が { 3, 4, 0 } を格納している場合、その数字は "$55555555555555555,4444,333.00%" のようにグループ化されます。

使用例

[Visual Basic, C#, C++] PercentGroupSizes プロパティの変更による影響を次のコード例に示します。

 
Imports System
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 [Double] = 123456789012345.6789
      Console.WriteLine(myInt.ToString("P", nfi))

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

   End Sub 'Main 

End Class 'NumberFormatInfoSample


'This code produces the following output.

'

'12,345,678,901,234,600.00 %

'1234,5678,9012,346,00.00 %

'123456789012,346,00.00 %



[C#] 
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 (".").
      Double myInt = 123456789012345.6789;
      Console.WriteLine( myInt.ToString( "P", nfi ) );

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

   }
}


/* 
This code produces the following output.

12,345,678,901,234,600.00 %
1234,5678,9012,346,00.00 %
123456789012,346,00.00 %
*/
   

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo * MyCI = new CultureInfo(S"en-US", false);
   NumberFormatInfo* nfi = MyCI -> NumberFormat;

   // Displays a value with the default separator (S".").
   Double myInt = 123456789012345.6789;
   Console::WriteLine(myInt.ToString(S"P", nfi));

   // Displays the same value with different groupings.
   Int32 mySizes1[] = {2, 3, 4};
   Int32 mySizes2[] = {2, 3, 0};
   nfi -> PercentGroupSizes = mySizes1;
   Console::WriteLine(myInt.ToString(S"P", nfi));
   nfi -> PercentGroupSizes = mySizes2;
   Console::WriteLine(myInt.ToString(S"P", nfi));
}
/*
This code produces the following output.

12, 345, 678, 901, 234, 600.00 %
1234, 5678, 9012, 346, 00.00 %
123456789012, 346, 00.00 %
*/ 

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

NumberFormatInfo クラス | NumberFormatInfo メンバ | System.Globalization 名前空間 | PercentDecimalDigits | PercentDecimalSeparator | PercentGroupSeparator | PercentSymbol | PercentNegativePattern | PercentPositivePattern | CurrencyGroupSizes | NumberGroupSizes