How-To Geek
Format a String as Currency in C#
When building a string for output to a web page, it’s useful to format any currency value in a human-friendly money format. This is extremely easy in C#.
The system format string works like this: {0:C}
For example, the following code example:
decimal moneyvalue = 1921.39m; string html = String.Format("Order Total: {0:C}", moneyvalue); Console.WriteLine(html);
Outputs the following:
Order Total: $1,921.39
It’s worth noting that you must pass in a numeric value to the String.Format statement. If you pass in a string value, it won’t format correctly. If your currency value is in a string, you need to convert it into a double first.
Got Feedback? Join the discussion at discuss.howtogeek.com
Comments (23)
Programmer by day, geek by night, The Geek, also known as Lowell Heddings, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on Google+ if you'd like.
- Published 11/27/06




You can also use:
decimal moneyvalue = 1921.39m;
string html = “Order Total: ” + moneyvalue.ToString(“C”);
Console.WriteLine(html);
how do i format the currency value i.e from $ to £ that isd from dollars to pounds using the string.format ?
I can give help I think look at control panel , regional option and look you can change your currency value there
Ultimate one ..really helpful
decimal moneyvalue = 1921.39m;
You can use
moneyvalue.ToString(“N”)
instead of
moneyvalue.ToString(“C”)
by this way you get the formatted string just like currency, without Currency sign
by this way you get the formatted string just like currency, without Currency sign
thanks i searching about this :)
Thanks for a great article, direct and to the point!
-Joseph Marinaccio
Marinaccio Family Design
Thank you.
Is there a way to force the currency to be a specific one? Just because some has different regional settings it does not change the fact that a price is listed in (for example)pound.
You can provide IFormatProvider. In this case you can do something like this
using System.Globalization;
decimal = moneyValue = 100.00m;
string output = String.Format(CultureInfo.CurrentUICulture, “{0:C}”, moneyValue);
With the above approach you don’t need to worry about culture specific format.
use this method
public static string formatmoney(Decimal d)
{
return String.Format(CultureInfo.CreateSpecificCulture(“en-us”), “{0:C}”, d);
}
thnx Barbaros Alp ..
thanks jemala !!
great help….
How if I’m writing a Curreny Conversion program on the Console of Visual Basic can i get the Dollar sign? I can get the pound sign by using {0:c2} but after the conversion I can’t get it to change to show a $ sign, I don’t know the code i need to write, Anybody know where I’m going wrong? Could really do with the help..
Thanks everyone
Andy
Can anyone help me in getting $ sign for a -ve amount.
i.e. I want to conevrt -1000m to $ -1000.00 or (-) $ 1000.00 using any Format conversion.
Thanks in advance.
Thanxssssss
Thank you.
Thanks this is just what I needed to format my moneys.
Also, you can define how many decimal show.
For example:
No decimal String.Format(“Order Total: {0:C0}”, moneyvalue);
Four decimal String.Format(“Order Total: {0:C4}”, moneyvalue);
thank for help this site
MaxPrice.ToString(“#,##,##,##”)
hiiiiiiiii
Where is my coding going wrong here then, when I compile it using the .NET command prompt and run it correctly says “the cash value you entered was xx.xx” but doesnt have a £ sign there?? HELP.
string cashValue;
Console.WriteLine(“Please Enter a Cash Value”);
cashValue = Console.ReadLine();
Convert.ToDecimal(cashValue);
Console.WriteLine(“The cash value you entered was {0:c}” , cashValue);