C# Currency ("C") Format

In this chapter you will learn:

  1. How to use Currency ("C") Format
  2. Example to use currency format

Description

The "C" (or currency) format specifier formats a number as currency.

Item Value
Format specifier "C" or "c"
Supported Type All numeric types
ResultA currency value.
Precision specifier Number of decimal digits. The default precision is defined by the NumberFormatInfo.CurrencyDecimalDigits property.
Default precision specifier Defined by System.Globalization.NumberFormatInfo.

Examples:

ValueFormatFormatted
123.456("C", en-US) $123.46
-123.456 ("C3", en-US) ($123.456)

If the value has more than the specified or default number of decimal places, the fractional value is rounded in the result string.

The following table lists the NumberFormatInfo properties that control the formatting of the returned string.

  • CurrencyPositivePattern
  • CurrencyNegativePattern
  • CurrencySymbol
  • CurrencyDecimalDigits
  • CurrencyDecimalSeparator
  • CurrencyGroupSeparator
  • CurrencyGroupSizes
  • NegativeSign

Example


using System;/*w w w  .  j  av a  2s.c o m*/
using System.Globalization;
class MainClass
{
   static void Main()
   {
        double value = 12345.6789;
        Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));
        
        Console.WriteLine(value.ToString("C3", CultureInfo.CurrentCulture));
        
        Console.WriteLine(value.ToString("C3", CultureInfo.CreateSpecificCulture("da-DK")));
   }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Use Decimal ("D") Format
  2. Example to Use Decimal ("D") Format
Home »
  C# Tutorial »
    C# Language »
      C# Standard Data Type Format
C# Standard Numeric Format
C# Currency ("C") Format
C# Decimal ("D") Format
C# Exponential ("E") Format
C# Fixed-Point ("F") Format
C# General ("G") Format
C# Hexadecimal ("X") Format
C# Numeric ("N") Format
C# Percent ("P") Format
C# Round-trip ("R") Format