Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle countries that use multiple currencies in .NET?

I have an application where I want to format a currency using the country's native currency formatting. Problem is, certain countries use multiple currencies, but .NET only assigns one currency per country. For example, Romania uses EUR and RON. When I get the currency info from .NET:

var cultureInfo = new CultureInfo("ro-RO");
Console.WriteLine("cultureInfo.NumberFormat.CurrencySymbol);

The output is leu, which is the RON currency type.

How would I get EUR for this case in .NET? I have the 3-letter ISO currency code (EUR) and the country language (ro-RO) but I don't know how to use this info to get a correctly-formatted euros currency string.

like image 983
Daniel T. Avatar asked Jun 20 '12 00:06

Daniel T.


1 Answers

You can replace currency symbol with a custom one (leu to euro in this case)

NumberFormatInfo LocalFormat = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
LocalFormat.CurrencySymbol = "€";

decimal money = 100;
Console.WriteLine(money.ToString("c", LocalFormat));
like image 89
fenix2222 Avatar answered Nov 14 '22 22:11

fenix2222