views:

49

answers:

2

If I have something like:

   Decimal moneyAmount = -1522;

and then call

moneyAmount.toString("c");

It will return something like:

($1,522)

Instead, I wish for there to be a negative sign and no paraenthesis. How can I modify what format provider I send to toString() so I can achieve the following effect:

-$1,522

A: 

A similar question was asked and answered here

Arkain
+2  A: 

Taken from: http://keithdevens.com/weblog/archive/2007/Jun/04/C-sharp.currency

// set currency format
string curCulture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
System.Globalization.NumberFormatInfo currencyFormat = new System.Globalization.CultureInfo(curCulture).NumberFormat;
currencyFormat.CurrencyNegativePattern = 1;

number.ToString("c", currencyFormat);
// or string.Format(currencyFormat, "{0:c}", number);
STW