NumberFormatInfo.PercentGroupSizes Właściwość

Definicja

Pobiera lub ustawia liczbę cyfr w każdej grupie z lewej strony wartości procentowych dziesiętnych.

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()

Wartość właściwości

Int32[]

Liczba cyfr w każdej grupie z lewej strony separatora dziesiętnego w wartościach procentowych. Wartością InvariantInfo domyślną dla jest tablica jednowymiarowa z tylko jednym elementem, który jest ustawiony na 3.

Wyjątki

Właściwość jest ustawiana na null wartość .

Właściwość jest ustawiana, a tablica zawiera wpis, który jest mniejszy niż 0 lub większy niż 9.

-lub-

Właściwość jest ustawiana, a tablica zawiera wpis inny niż ostatni wpis, który jest ustawiony na 0.

Właściwość jest ustawiana, a NumberFormatInfo obiekt jest tylko do odczytu.

Przykłady

W poniższym przykładzie pokazano efekt zmiany PercentGroupSizes właściwości .

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".").
   Double myInt = 123456789012345.6789;
   Console::WriteLine( myInt.ToString( "P", nfi ) );
   
   // Displays the same value with different groupings.
   array<Int32>^mySizes1 = {2,3,4};
   array<Int32>^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 %
*/
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 %

Uwagi

Właściwość jest używana z ciągiem standardowego formatu "P" do definiowania liczby PercentGroupSizes cyfr, które pojawiają się w grupach całkowitoapowodowych. Aby uzyskać więcej informacji, zobacz Ciągi standardowego formatu liczbowego. Każdy element tablicy jednowymiarowej musi być liczbą całkowitą z zakresów od 1 do 9. Ostatni element może mieć 0.

Pierwszy element tablicy definiuje liczbę elementów w najmniej znaczącej grupie cyfr natychmiast po lewej stronie tablicy PercentDecimalSeparator . Każdy kolejny element odwołuje się do następnej istotnej grupy cyfr z lewej strony poprzedniej grupy. Jeśli ostatni element tablicy nie jest 0, pozostałe cyfry są grupowane na podstawie ostatniego elementu tablicy. Jeśli ostatni element ma 0, pozostałe cyfry nie są grupowane.

Jeśli na przykład tablica zawiera { 3, 4, 5 }, cyfry są grupowane podobnie do "55 55555,55555,55555,4444,333,00%". Jeśli tablica zawiera { 3, 4, 0 }, cyfry są grupowane podobnie do "55555555555555555,4444,333,00%".

Dotyczy

Zobacz też