NumberFormatInfo.CurrencyGroupSizes Proprietà

Definizione

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

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

Valore della proprietà

Int32[]

Numero di cifre in ciascun gruppo che si trova a sinistra del separatore decimale nei valori di valuta. 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 CurrencyGroupSizes 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".").
   Int64 myInt = 123456789012345;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
   
   // Displays the same value with different groupings.
   array<Int32>^mySizes1 = {2,3,4};
   array<Int32>^mySizes2 = {2,3,0};
   nfi->CurrencyGroupSizes = mySizes1;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
   nfi->CurrencyGroupSizes = mySizes2;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
}

/* 
This code produces the following output.

$123, 456, 789, 012, 345.00
$12, 3456, 7890, 123, 45.00
$1234567890, 123, 45.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 (".").
      Int64 myInt = 123456789012345;
      Console.WriteLine( myInt.ToString( "C", nfi ) );

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


/*
This code produces the following output.

$123,456,789,012,345.00
$12,3456,7890,123,45.00
$1234567890,123,45.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 Int64 = 123456789012345
      Console.WriteLine(myInt.ToString("C", nfi))

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

   End Sub

End Class

 
'This code produces the following output.
'
'$123,456,789,012,345.00
'$12,3456,7890,123,45.00
'$1234567890,123,45.00

Commenti

La CurrencyGroupSizes proprietà viene usata con la stringa di formato standard "C" per definire il numero di cifre visualizzate nei gruppi integrali. Per altre informazioni, vedere Stringhe di formato numerico standard. Ogni elemento della matrice unidimensionale deve essere un 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 dell'oggetto CurrencyDecimalSeparator. Ogni elemento successivo fa riferimento al gruppo significativo successivo 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,5555555,555555,5555555,44444,333.00". Se la matrice contiene { 3, 4, 0 }, le cifre vengono raggruppate in modo simile a "$55555555555555555555555555555555,4444,333.00".

Si applica a

Vedi anche