Had a bit of a problem today. After importing a bunch of transactions I needed to display the corresponding currency symbol. The problem was when you import OFX transactions, the currency is in the ISO 4217 three letter format. Basically the little bit of LINQ below will search through all the culture infos until it finds one with the correct ISO Currency symbol. Its little things like this that make me love linq!
RegionInfo regionInfo = (from c in CultureInfo.GetCultures(CultureTypes.InstalledWin32Cultures)
let r = new RegionInfo(c.LCID)
where r.ISOCurrencySymbol == "GBP"
select r).First();
Hope this is helpful to someone!
Filed under: .net, c#, linq, ofx , linq c# money currency ofx
Thanks that helped! Was unaware of the RegionInfo.ISOCurrencySymbol.
Helped me a lot. And I was actually only wondering if I could get all the cultures and sort them through a query.
Don’t you love LINQ?
You can actually make it simpler than this, since the iso currency code is the two letter country code followed by a single digit currency id the following will work:
string currencysymbol=
new RegionInfo(CurrencyCode.Substring(0, 2)).CurrencySymbol;
Stop!!! You can’t do it the way I just suggested due to pan-national currencies. Hope no one followed my advice!