Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying currency in C#

I need to display data values in US currency format. Meaning 190.8 should display as $190.80. For some reason I cant figure out how to do this. Any advice?

like image 739
user279521 Avatar asked Jun 18 '10 12:06

user279521


2 Answers

You could explicitly specify the US culture like so:

string.Format(CultureInfo.GetCultureInfo("en-US"), "{0:C}", decimalValue)

The C indicates the default currency format for the specified culture, in this case exactly what you're after. If you want the US currency symbol with a continental European number format (comma instead of period) then your job would be harder of course...

like image 176
David M Avatar answered Sep 19 '22 07:09

David M


Standard Numeric Format Strings

   decimal moneyvalue = 1921.39m;
    string html = String.Format("Order Total: {0:C}", moneyvalue);
    Console.WriteLine(html);

or

double value = 12345.6789;
Console.WriteLine(value.ToString("C", CultureInfo.CurrentCulture));//CultureInfo.GetCultureInfo("en-US")
// current culture is English (United States):
//       $12,345.68
like image 41
Pranay Rana Avatar answered Sep 20 '22 07:09

Pranay Rana