Get the currency from current culture?

纵然是瞬间 提交于 2019-11-28 07:08:18

Use the RegionInfo.ISOCurrencySymbol property. For example:

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

Output: "USD"

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)

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
string isoCurrencySymbol = RegionInfo.CurrentRegion.ISOCurrencySymbol;

You can basically use CultureInfo class

CultureInfo ci = new CultureInfo(UICulture);
var symbol = ci.NumberFormat.CurrencySymbol;
    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;
                    }
                }
        }

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!