Reputation: 383
I am using the following code to return my itemValue as currency.
Return String.Format("{0:C}", itemValue)
But this will return a string formatted as Dollar - is there any way to format this to return Pound Sterling?
Thanks, Guy
Upvotes: 2
Views: 2487
Reputation: 36
There is simpler method. As float, double, decimal etc. type has own formatting, throughout ToString() method. For example:
double itemValue = 102.35;
Console.WriteLine(itemValue.ToString("C", new CultureInfo("en-GB")));
Upvotes: 0
Reputation: 735
The string formatter takes currency and number formatting from the current culture of your machine. You can either:
Set the culture explicit in the formatting:
Return String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-GB"), "{0:C}", itemValue)
Upvotes: 2
Reputation: 3681
Change the CurrentCulture as @Steve suggests or just use it like this:
Return itemValue.ToString("C", System.Globalization.CultureInfo.GetCultureInfo("en-gb"))
Upvotes: 7
Reputation: 216313
Before asking for the formatting change the CurrentCulture of your thread
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB")
Upvotes: 4