Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Currency Symbol after values

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.

like image 210
R100 Avatar asked Mar 11 '11 12:03

R100


People also ask

Should currency symbol be before or after Number?

In American English, the currency symbol is placed before the amount; the same is true for British English. It is $20, not 20$.


2 Answers

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

like image 162
Oleks Avatar answered Nov 15 '22 13:11

Oleks


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

like image 40
Kim Avatar answered Nov 15 '22 12:11

Kim