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.
Daily Email Updates
You can get our how-to articles in your inbox each day for free. Just enter your name and email below:
| Similar Articles | Featured Wiki Articles |
|
|
| Latest Software Reviews | Quick Linux Tips |
| Geek Arcade | Popular Forum Threads |


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);
}