I need to get the System.Globalization.CultureInfo for different Currency Codes.
Examples: EUR, GBP, USD
Currently I am doing the following inside a switch statement based on this 3 letter currency code, obviously this is not the way to do it:
var ci = new System.Globalization.CultureInfo("en-US");
Anyone have a clean way to achieve the same results using the currency code's instead?
static IEnumerable<CultureInfo> GetCultureInfosByCurrencySymbol(string currencySymbol)
{
if (currencySymbol == null)
{
throw new ArgumentNullException("currencySymbol");
}
return CultureInfo.GetCultures(CultureTypes.SpecificCultures)
.Where(x => new RegionInfo(x.LCID).ISOCurrencySymbol == currencySymbol);
}
For example
foreach (var culture in GetCultureInfosByCurrencySymbol("GBP"))
{
Console.WriteLine(culture.Name);
}
prints:
cy-GB
gd-GB
en-GB
Short: That's not possible. EUR for example would map to de-DE, fr-FR, nl-NL and other countries. There is no mapping from Currency to culture, because multiple countries share currencies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With