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
> I am looking to globalize a website that contains currencies. I am
> going to be using the ToString(string) method to format the currency
[quoted text clipped - 4 lines]
>
> Thanks
doomsday123@gmail.com - 24 Jan 2008 17:38 GMT
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.
Adrian - 24 Jan 2008 18:46 GMT
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
>
[quoted text clipped - 6 lines]
> or atleast show USD somewhere when a currency is being formated by the
> tostring method.
Arne Vajhøj - 25 Jan 2008 03:12 GMT
> What im talking about is instead of the
>
[quoted text clipped - 6 lines]
> 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