Changing Currency Symbol location in System.Globalization.NumberFormatInfo

丶灬走出姿态 提交于 2019-12-23 18:52:52

问题


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

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

From all I've seen, the Euro needs to be on the left, and my business requirements mandate that it is on the left. However, there is no way to programmatically set this value.

Any ideas on how I can set this value easily? I have started to take a US culture object and copy everything from the French culture over to it, since we still want all the other French settings, except for the Euro on the right value. But this method is very time consuming and frustrating.

Thanks!


回答1:


Clone the original and then modify 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"

Note that this will only affect that specific CultureInfo object, not the one obtained for French in general - so you'll need to make sure you use it everywhere.



来源:https://stackoverflow.com/questions/1446273/changing-currency-symbol-location-in-system-globalization-numberformatinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!