Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / January 2008

Tip: Looking for answers? Try searching our database.

Currency Format

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
doomsday123@gmail.com - 24 Jan 2008 16:58 GMT
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
Adrian - 24 Jan 2008 17:29 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.