开发者

How can I modify the currency formatter to allow negative money amounts in C#?

开发者 https://www.devze.com 2023-01-04 20:33 出处:网络
If I have something like: Decimal moneyAmount = -1522; and then call moneyAmount.t开发者_如何转开发oString(\"c\");

If I have something like:

   Decimal moneyAmount = -1522;

and then call

moneyAmount.t开发者_如何转开发oString("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


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消