Show Currency Symbol after values

心不动则不痛 提交于 2020-01-14 09:41:29

问题


I am using CultureInfo methods to successfully format all different currencies into their correct format.

But on some exceptions, such as EUR and SEK currencies I need to be able to add them after the value. At the moment my CultureInfo is formatting them in the following way: "SEK 1.00,00" when it needs to be "1.00,00 SEK".

Any help is appreciated.


回答1:


All you need is to change the NumberFormatInfo.CurrencyPositivePattern and NumberFormatInfo.CurrencyNegativePattern properties for the culture.

Just clone the original culture:

CultureInfo swedish = new CultureInfo("sv-SE");
swedish = (CultureInfo)swedish.Clone();
swedish.NumberFormat.CurrencyPositivePattern = 3;
swedish.NumberFormat.CurrencyNegativePattern = 3;

and then

var value = 123.99M;
var result = value.ToString("C", swedish);

should give you desired result. This should get you:

123,99 kr




回答2:


Be careful about the CurrencyNegativePattern

This code

CultureInfo swedish = new CultureInfo("sv-SE");
swedish = (CultureInfo)swedish.Clone();
swedish.NumberFormat.CurrencyPositivePattern = 3;
swedish.NumberFormat.CurrencyNegativePattern = 3;

Will give you

134,99 kr.

kr.134,99kr.-

Changing CurrencyNegativePattern to 8

swedish.NumberFormat.CurrencyNegativePattern = 8;

Will give you

134,99 kr.

-134,99 kr.

More info https://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern(v=vs.110).aspx



来源:https://stackoverflow.com/questions/5272760/show-currency-symbol-after-values

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