Fle*_*ece 2 c# string-formatting
如果我有类似的东西:
Decimal moneyAmount = -1522;
Run Code Online (Sandbox Code Playgroud)
然后打电话
moneyAmount.toString("c");
Run Code Online (Sandbox Code Playgroud)
它将返回如下内容:
($ 1,522名)
相反,我希望有一个消极的迹象,没有假设.如何修改我发送到toString()的格式提供程序,以便我可以实现以下效果:
- $ 1,522名
摘自: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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2444 次 |
| 最近记录: |