Get the currency from current culture?

后端 未结 8 1361
渐次进展
渐次进展 2020-12-03 04:25

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

相关标签:
8条回答
  • 2020-12-03 04:37

    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
    
    0 讨论(0)
  • 2020-12-03 04:42

    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

    0 讨论(0)
  • 2020-12-03 04:45

    this worked for me.

    var c = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
          .Select(t=> new RegionInfo(t.LCID))
          .Where(t=>t.ThreeLetterISORegionName  == "USA")
          .FirstOrDefault();
    
    0 讨论(0)
  • 2020-12-03 04:46

    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)

    0 讨论(0)
  • 2020-12-03 04:52

    You can basically use CultureInfo class

    CultureInfo ci = new CultureInfo(UICulture);
    var symbol = ci.NumberFormat.CurrencySymbol;
    
    0 讨论(0)
  • 2020-12-03 04:53
        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;
                        }
                    }
            }
    
    0 讨论(0)
提交回复
热议问题