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?
+1
A:
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
Pranay Rana
2010-06-18 12:21:12
+15
A:
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...
David M
2010-06-18 12:21:14
-1 for the wrong data type for a currency value.
David M
2010-06-18 12:44:33
A:
string usCurrency = (190.8m).ToString("c", CultureInfo.GetCultureInfo("en-US"));
lc
2010-06-18 12:25:23
A:
decimal d = 190.8M;
string displayData = d.ToString("c");
If your CurrentCulture
is already US there's no need to explicitly supply it.
David Neale
2010-06-18 12:46:17