NumberFormatInfo.CurrencyDecimalDigits Propriété

Définition

Obtient ou définit le nombre de décimales à utiliser dans les valeurs de devise.

public:
 property int CurrencyDecimalDigits { int get(); void set(int value); };
public int CurrencyDecimalDigits { get; set; }
member this.CurrencyDecimalDigits : int with get, set
Public Property CurrencyDecimalDigits As Integer

Valeur de propriété

Nombre de décimales à utiliser dans les valeurs de devise. La valeur par défaut de InvariantInfo est 2.

Exceptions

La propriété est définie sur une valeur inférieure à 0 ou supérieure à 99.

La propriété est définie et l’objet NumberFormatInfo est en lecture seule.

Exemples

L’exemple suivant illustre l’effet de la modification de la CurrencyDecimalDigits propriété.

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 negative value with the default number of decimal digits (2).
   Int64 myInt = -1234;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
   
   // Displays the same value with four decimal digits.
   nfi->CurrencyDecimalDigits = 4;
   Console::WriteLine( myInt.ToString( "C", nfi ) );
}

/* 
This code produces the following output.

($1, 234.00)
($1, 234.0000)
*/
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 negative value with the default number of decimal digits (2).
      Int64 myInt = -1234;
      Console.WriteLine( myInt.ToString( "C", nfi ) );

      // Displays the same value with four decimal digits.
      nfi.CurrencyDecimalDigits = 4;
      Console.WriteLine( myInt.ToString( "C", nfi ) );
   }
}


/*
This code produces the following output.

($1,234.00)
($1,234.0000)
*/
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 negative value with the default number of decimal digits (2).
      Dim myInt As Int64 = - 1234
      Console.WriteLine(myInt.ToString("C", nfi))

      ' Displays the same value with four decimal digits.
      nfi.CurrencyDecimalDigits = 4
      Console.WriteLine(myInt.ToString("C", nfi))

   End Sub

End Class


' This code produces the following output.
'
' ($1,234.00)
' ($1,234.0000)

Remarques

La CurrencyDecimalDigits propriété est utilisée avec la chaîne de format standard « C » sans spécificateur de précision dans les opérations de mise en forme numérique. Il définit le nombre par défaut de chiffres fractionnaires qui apparaissent après le séparateur décimal. Cette valeur est remplacée si un spécificateur de précision est utilisé. Pour plus d’informations, consultez Chaînes de format numériques standard.

S’applique à

Voir aussi