Currency Format

  • Thread starter Thread starter doomsday123
  • Start date Start date
D

doomsday123

I am looking to globalize a website that contains currencies. I am
going to be using the ToString(string) method to format the currency
which uses the currenct CultureInfo class. Is there any way to get the
Currency code such as USD or EUR appended to the front of the currency
using this method. I looked at the NumberFormatInfo class and didnt
see anything of use.

Thanks
 
In EN-US Culture
double arg = 123,456,789.00
Console.WriteLine(arg.ToString("C")); $123,456,789.00
Console.WriteLine(arg.ToString("E")); 1.234568E+008
Console.WriteLine(arg.ToString("P")); 12,345,678,900.00%
Console.WriteLine(arg.ToString("N")); 123,456,789.00
Console.WriteLine(arg.ToString("F")); 123456789.00

You will want to use decimal though
 
What im talking about is instead of the

$123,456,789.00

I want to show

USD $123,456,789.00

or atleast show USD somewhere when a currency is being formated by the
tostring method.
 
ToString(“USD $ ###.##”);

{1:C} the second argument will be formatted as a currency value. C after
the : is the formatting code or format specifier
{0:D3} the first argument will be formatted as a three digit decimal,
any number fewer than three digits will have leading zeros
{0,4} the first argument will have four characters and be right aligned
{0,-4} the first argument will have four characters and be left aligned
 
What im talking about is instead of the

$123,456,789.00

I want to show

USD $123,456,789.00

or atleast show USD somewhere when a currency is being formated by the
tostring method.

You can control it completely if you want to.

CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
NumberFormatInfo nfi = (NumberFormatInfo)ci.NumberFormat.Clone();;
nfi.CurrencySymbol = "DKK";
ci.NumberFormat = nfi;
decimal x = 123.45m;
Console.WriteLine(String.Format("{0:c}", x));
Console.WriteLine(String.Format(ci, "{0:c}", x));

outputs:

kr 123,45
DKK 123,45

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top