3 Digit currency code to currency symbol

前端 未结 9 1206
逝去的感伤
逝去的感伤 2020-12-04 10:19

In C# is it possible to get a currency symbol, like \'£\', from the 3 character currency code, in this case \'GBP\'?

Is this possible either in SQL Server or in C#?<

9条回答
  •  死守一世寂寞
    2020-12-04 10:56

    With the help of this thread I made a short string extension method

    public static string ToCurrencySymbol(this string ISOCurrency)
    {            
        RegionInfo region = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID)).FirstOrDefault(p => p.ISOCurrencySymbol == ISOCurrency);
        return region?.ISOCurrencySymbol ?? ISOCurrency;
    }
    

提交回复
热议问题