guyh92
guyh92

Reputation: 383

String.Format format specifer as Pound Sterling

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

Answers (4)

Kirill Kryazhnikov
Kirill Kryazhnikov

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

Bebben
Bebben

Reputation: 735

The string formatter takes currency and number formatting from the current culture of your machine. You can either:

  1. Change the culture information on your computer
  2. Set the culture explicit in the formatting:

    Return String.Format(System.Globalization.CultureInfo.GetCultureInfo("en-GB"), "{0:C}", itemValue)

Upvotes: 2

acfrancis
acfrancis

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

Steve
Steve

Reputation: 216313

Before asking for the formatting change the CurrentCulture of your thread

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB")

Upvotes: 4

Related Questions