Hi guys,
Firstly let’s clarify what currency symbols and currency codes are.
Currency symbols are symbols that are used to represent a currency and it can vary from each country.
See below some currency symbols as examples:
- € – Euro
- £ – Pounds
- R$ – Real
The currency code or the ISO 4217 is a international standard that sets codes of 3 characters for currencies.
See below some examples of currency codes:
- EUR – Euro
- GBP – Pounds
- BRL – Real
Now let’s write a function using C# that will enable you to get a currency symbol given a currency code. This function can be very useful for you that is working with international systems.
To convert the currency code to currency symbol we will use the System.Globalization.
See the function below:
/// <summary> /// Method used to return a currency symbol. /// It receive as a parameter a currency code (3 digits). /// </summary> /// <param name="code">3 digits code. Samples GBP, BRL, USD, etc.</param> public static string GetCurrencySymbol(string code) { System.Globalization.RegionInfo regionInfo = (from culture in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.InstalledWin32Cultures) where culture.Name.Length > 0 && !culture.IsNeutralCulture let region = new System.Globalization.RegionInfo(culture.LCID) where String.Equals(region.ISOCurrencySymbol, code, StringComparison.InvariantCultureIgnoreCase) select region).First(); return regionInfo.CurrencySymbol; }
Click on this link to know more about Currency Symbol.
Click on this link to know more about System.Globalization Namespace.
Click on this link to know more about CultureInfo Class.
Click on this link to know more about the ISO 4217.
Thanks for reading.
Like and Share if you found it may be useful to someone you know!
Would you like to check the Portuguese version?
Clique on the Brazilian flag ->