Export (0) Print
Expand All

NumberFormatInfo.CurrencyDecimalDigits Property

Indicates the number of decimal places to use in currency values.

[Visual Basic]
Public Property CurrencyDecimalDigits As Integer
[C#]
public int CurrencyDecimalDigits {get; set;}
[C++]
public: __property int get_CurrencyDecimalDigits();
public: __property void set_CurrencyDecimalDigits(int);
[JScript]
public function get CurrencyDecimalDigits() : int;
public function set CurrencyDecimalDigits(int);

Property Value

The number of decimal places to use in currency values. The default for InvariantInfo is 2.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException The property is being set to a value that is less than 0 or greater than 99.
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.

Example

[Visual Basic, C#, C++] The following code example demonstrates the effect of changing the CurrencyDecimalDigits property.

[Visual Basic] 
Imports System
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 'Main 

End Class 'NumberFormatInfoSample


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


[C#] 
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)
*/
   

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo * MyCI = new CultureInfo(S"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(S"C", nfi));

   // Displays the same value with four decimal digits.
   nfi -> CurrencyDecimalDigits = 4;
   Console::WriteLine(myInt.ToString(S"C", nfi));
}
/* 
This code produces the following output.

($1, 234.00)
($1, 234.0000)
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

NumberFormatInfo Class | NumberFormatInfo Members | System.Globalization Namespace | CurrencyDecimalSeparator | CurrencyGroupSeparator | CurrencyGroupSizes | CurrencySymbol | CurrencyNegativePattern | CurrencyPositivePattern | NumberDecimalDigits | PercentDecimalDigits

Show:
© 2014 Microsoft