NumberFormatInfo.PercentGroupSizes Proprietà

Definizione

Ottiene o imposta il numero di cifre in ciascun gruppo che si trova a sinistra del separatore decimale nei valori percentuali.

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

Valore della proprietà

Int32[]

Numero di cifre in ciascun gruppo che si trova a sinistra del separatore decimale nei valori percentuali. L'impostazione predefinita per InvariantInfo è una matrice unidimensionale con un solo elemento, che è impostato su 3.

Eccezioni

La proprietà viene impostata su null.

La proprietà viene impostata e la matrice contiene una voce minore di 0 o maggiore di 9.

-oppure-

La proprietà viene impostata e la matrice contiene una voce, diversa da quella precedente, che è impostata su 0.

La proprietà viene impostata e l'oggetto NumberFormatInfo è di sola lettura.

Esempio

Nell'esempio seguente viene illustrato l'effetto della modifica della PercentGroupSizes proprietà .

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 %

Commenti

La PercentGroupSizes proprietà viene utilizzata con la stringa di formato standard "P" per definire il numero di cifre visualizzate nei gruppi integrali. Per altre informazioni, vedere Stringhe di formato numerico standard. Ogni elemento nella matrice unidimensionale deve essere un numero intero compreso tra 1 e 9. L'ultimo elemento può essere 0.

Il primo elemento della matrice definisce il numero di elementi nel gruppo meno significativo di cifre immediatamente a sinistra di PercentDecimalSeparator. Ogni elemento successivo fa riferimento al successivo gruppo significativo di cifre a sinistra del gruppo precedente. Se l'ultimo elemento della matrice non è 0, le cifre rimanenti vengono raggruppate in base all'ultimo elemento della matrice. Se l'ultimo elemento è 0, le cifre rimanenti non vengono raggruppate.

Ad esempio, se la matrice contiene { 3, 4, 5 }, le cifre sono raggruppate in modo simile a "55.55555,55555,55555,4444,333.00%". Se la matrice contiene { 3, 4, 0 }, le cifre sono raggruppate in modo simile a "5555555555555555555555,4444,333,00%".

Si applica a

Vedi anche