NumberFormatInfo.PercentGroupSizes Propiedad

Definición

Obtiene o establece el número de dígitos en cada grupo a la izquierda de la coma decimal en valores de porcentaje.

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

Valor de propiedad

Int32[]

Número de dígitos en cada grupo a la izquierda de la coma decimal en valores de porcentaje. El valor predeterminado de InvariantInfo es una matriz unidimensional con un único elemento, que se establece en 3.

Excepciones

La propiedad se establece en null.

La propiedad se establece y la matriz contiene una entrada que es menor que 0 o mayor que 9.

O bien

La propiedad se establece y la matriz contiene una entrada distinta a la última entrada que se establece en 0.

La propiedad se está estableciendo y el objeto NumberFormatInfo es de solo lectura.

Ejemplos

En el ejemplo siguiente se muestra el efecto de cambiar la PercentGroupSizes propiedad .

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 %

Comentarios

La propiedad se usa con la cadena de formato estándar "P" para definir el número de dígitos PercentGroupSizes que aparecen en grupos enteros. Para más información, vea Cadenas de formato numérico estándar. Cada elemento de la matriz unidimensional debe ser un entero del 1 al 9. El último elemento puede ser 0.

El primer elemento de la matriz define el número de elementos del grupo de dígitos menos significativo inmediatamente a la izquierda de PercentDecimalSeparator . Cada elemento posterior hace referencia al siguiente grupo significativo de dígitos a la izquierda del grupo anterior. Si el último elemento de la matriz no es 0, los dígitos restantes se agrupan en función del último elemento de la matriz. Si el último elemento es 0, los dígitos restantes no se agrupan.

Por ejemplo, si la matriz contiene { 3, 4, 5 }, los dígitos se agrupan de forma similar a "55,55555,55555,5555,4444,333.00%". Si la matriz contiene { 3, 4, 0 }, los dígitos se agrupan de forma similar a "55555555555555,4444,333,00%".

Se aplica a

Consulte también