58

Is there a way to get current information dynamically from the apps culture settings? Basically if the user has set the culture to US I want to know the currency is dollars, or if they have it set to UK I want to pound sterling etc... etc..

This is so I can send this information to PayPal when a payment is being made

abatishchev
  • 98,240
  • 88
  • 296
  • 433
YodasMyDad
  • 9,248
  • 24
  • 76
  • 121

8 Answers8

97

Use the RegionInfo.ISOCurrencySymbol property. For example:

  var ri = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
  Console.WriteLine(ri.ISOCurrencySymbol);

Output: "USD"

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
43

You can get the symbol from CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol, but I doubt this is enough; you may need to maintain a separate list per culture. Or just let the user tell you what they want to pay in (for example, they might be away from home, etc, so the culture of the PC in some hotel lounge isn't what is on their credit card)

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
27

Once you have the CultureInfo ci object, you can ask such as

ci.NumberFormat.CurrencySymbol

For current culture, you will simply do

CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol
Fadrian Sudaman
  • 6,405
  • 21
  • 29
6
string isoCurrencySymbol = RegionInfo.CurrentRegion.ISOCurrencySymbol;
Cornel
  • 4,652
  • 15
  • 48
  • 57
  • 1
    The ISOCurrencySymbol is the 3-letter code (e.g., USD). The symbol or sign (e.g., $) as retrieved by NumberFormat.CurrencySymbol, is NOT unique. – Doug Domeny May 03 '12 at 14:18
  • Just a warning that CurrentRegion does NOT come from the current UI culture, and changing the culture of the current thread will not change CurrentRegion - https://learn.microsoft.com/en-us/dotnet/api/system.globalization.regioninfo.currentregion?view=netframework-4.8 To do that see the answer by @Hans Passant – herostwist Jul 02 '19 at 10:52
  • @herostwist for most app the OS setting is the one to use. So no issue. – Softlion Mar 20 '22 at 07:59
2

You can basically use CultureInfo class

CultureInfo ci = new CultureInfo(UICulture);
var symbol = ci.NumberFormat.CurrencySymbol;
Jan Remunda
  • 7,840
  • 8
  • 51
  • 60
  • 3
    Not good enough - sorry. THe currency symbol is not the currency - there is no requirement for that being unique. – TomTom May 04 '10 at 06:19
2
    public static string GetCurrencySymbol(string currency)
    {
        if (currency == null) return "";
        if (currency == "") return "";
        int i = 0;
        var regionInfo = new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID);
        foreach (var cultureInfo in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))
        {
            if (!cultureInfo.Equals(CultureInfo.InvariantCulture))
            {
                var regionCulture = new RegionInfo(cultureInfo.LCID);

                    if(regionCulture.ISOCurrencySymbol == currency)
                    {
                        //list.Add(regionCulture);
                        regionInfo = regionCulture;
                    }
                }
        }
Mike
  • 21
  • 1
1

this worked for me.

var c = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
      .Select(t=> new RegionInfo(t.LCID))
      .Where(t=>t.ThreeLetterISORegionName  == "USA")
      .FirstOrDefault();
Vishav Premlall
  • 456
  • 6
  • 22
0

http://help.outlook.com/en-us/140/system.globalization.regioninfo.currencynativename(VS.85).aspx

You'll want the RegionInfo.CurrencyNativeName, RegionInfo.CurrencyEnglishName or RegionInfo.ISOCurrencySymbol

Jeroen
  • 4,023
  • 2
  • 24
  • 40