Change the location of a currency symbol in System.Globalization.NumberFormatInfo

I created a CultureInfo object using the new CultureInfo ("fr-FR"). Now I have a number that I want to call. ToString ("C", FrenchCultureInfo). The resulting string puts € AFTER in a number. Why?

CultureInfo french = new CultureInfo("fr-FR");
double value = 1234.56;
string output = value.ToString("C", french);//output = "1 234,56 €"

Of all that I saw, the Euro should be on the left, and my business requirements require it to be on the left. However, there is no way to programmatically set this value.

Any ideas on how I can easily set this value? I began to accept the object of culture of the USA and copy everything from French culture, until we still do not want all other French settings, with the exception of the euro, to be correct. But this method is very laborious and frustrating.

Thanks!

+3
source share
1 answer

Clone the original, and then change it:

CultureInfo french = new CultureInfo("fr-FR");
french = (CultureInfo) french.Clone();
// Adjust these to suit
french.NumberFormat.CurrencyPositivePattern = 2;
french.NumberFormat.CurrencyNegativePattern = 2;
double value = 1234.56;
string output = value.ToString("C", french);//output = "€ 1 234,56"

Please note that this will only affect the specific object CultureInfo, not the one obtained for the French language in general, so you need to make sure that you use it everywhere.

+6
source

Source: https://habr.com/ru/post/1718061/


All Articles