我希望我的值(value)观显示在 View 中
喜欢:-$150.00
而不是:($150.00)
--
我想这就是我必须做的:
How do I display a negative currency in red?
但我不知道他所说的“BaseController类”是什么意思
最佳答案
这一切都归结为NumberFormatInfo.CurrencyNegativePattern
.当听起来您想要 1 时,您可能得到了值 0。
不清楚您当前使用的是用户的 CultureInfo
、服务器的还是其他的。但您始终可以克隆您正在使用的任何文化,然后修改 NumberFormatInfo
。
示例代码:
using System;
using System.Globalization;
class Test
{
static void Main()
{
var original = new CultureInfo("en-us");
// Prints ($5.50)
Console.WriteLine(string.Format(original, "{0:C}", -5.50m));
var modified = (CultureInfo) original.Clone();
modified.NumberFormat.CurrencyNegativePattern = 1;
// Prints -$5.50
Console.WriteLine(string.Format(modified, "{0:C}", -5.50m));
}
}
关于c# - 如何在 ASP NET MVC 中使用负数而不是括号显示货币?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19058873/