7

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.

3 Answers 3

9

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
  • 1
    Yes that works! Thanks Alex. Just so that I understand what you done. All I needed was to add CurrencyPositivePattern and CurrencyNegativePattern methods to move the currency symbol to the end?
    – R100
    Mar 11, 2011 at 12:47
  • 1
    @R100: yep, but these are the properties(not methods) of NumberFormatInfo class.
    – Oleks
    Mar 11, 2011 at 12:51
3

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

0
string.Format(CultureInfo.CurrentCulture, "{0:C}", moneyValue.DataAmount)
1
  • If this solves the problem, an explanation would make this a better answer Jan 20, 2020 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.