次の方法で共有


NumberFormatInfo.PercentGroupSizes プロパティ

定義

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

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

プロパティ値

Int32[]

10 進数の左にある各グループの桁数 (パーセント値)。 InvariantInfoの既定値は 1 次元配列で、要素は 1 つだけで、3 に設定されます。

例外

プロパティは nullに設定されています。

プロパティが設定されており、配列に 0 未満または 9 より大きいエントリが含まれています。

-又は-

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

プロパティが設定されており、 NumberFormatInfo オブジェクトは読み取り専用です。

次の例では、 PercentGroupSizes プロパティを変更した場合の効果を示します。

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 %
*/
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

End Class


'This code produces the following output.
'
'12,345,678,901,234,600.00 %
'1234,5678,9012,346,00.00 %
'123456789012,346,00.00 %

注釈

PercentGroupSizes プロパティは、整数グループに表示される桁数を定義するために、"P" 標準書式指定文字列と共に使用されます。 詳細については、「 標準数値書式指定文字列」を参照してください。 1 次元配列内のすべての要素は、1 ~ 9 の整数である必要があります。 最後の要素には 0 を指定できます。

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

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

適用対象

こちらもご覧ください