-2

I have a ddl with values that represent country codes. eg. BRA, THA, UKR, AUS etc. I need to get the preferred currency from localization settings for each of these.

I have tried checking the RegionInfo class and it is likely that the answer is somewhere in there. This link shows what i want https://www.iban.com/currency-codes

Is there any way to get the 3 digit currencyCode without using a table structure? i.e. from the pc or browser itself. Basically, if the user chooses their country as USA, then the currency should be fixed to USD. I can do this very easily with some sql. But i would like to do this without hitting the db. i.e. via RegionInfo or CultureInfo.

I cannot use new RegionInfo(System.Threading.Thread.CurrentThread.CurrentUICulture.LCID).ISOCurrencySymbol as it pulls from the server.

Vishav Premlall
  • 456
  • 6
  • 22

3 Answers3

2

There is a solution about it if that 3 letter is ISO standard you can apply this code

var c = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
      .Select(t=> new RegionInfo(t.LCID))
      .Where(t=>t.ThreeLetterISORegionName  == "USA")
      .FirstOrDefault();
Eldar
  • 9,781
  • 2
  • 10
  • 35
1

.NET has CultureInfo.NumberFormat.CurrencySymbol

RegionInfo us = new RegionInfo("en-US");
RegionInfo gb = new RegionInfo("en-GB");
RegionInfo fr = new RegionInfo("fr-FR");

Console.Out.WriteLine(us.CurrencySymbol); // $
Console.Out.WriteLine(gb.CurrencySymbol); // £
Console.Out.WriteLine(fr.CurrencySymbol); // €

Console.Out.WriteLine(us.ISOCurrencySymbol); // USD
Console.Out.WriteLine(gb.ISOCurrencySymbol); // GBP
Console.Out.WriteLine(fr.ISOCurrencySymbol); // EUR

The complete Region information is available here

Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115
-1

You will need to have access to a datastore somewhere.

Your choices are:

  1. database - which you've already discounted (probably as you don't want to maintain the dataset)

  2. hard code - again that requires you to maintain the dataset again.

  3. use an external data source - such as an API, where the third party can provide the data you require in response to an HTTP request. The bonus is that they also maintain the dataset for you (although there will be no guarantees of how regularly it is kept up to date).

I suggest that you have a look at:

https://restcountries.eu/

They provide a range of RESTful API endpoints that you could query to retrieve the currency code.

Tim Wooldridge
  • 193
  • 1
  • 3
  • 11