如何正确显示小数?
How to properly display decimal?
我正在寻找一种在我的视图中正确格式化和显示小数值的方法。
例如:123456789,9876
应该是123 456 789,99
。
有时我想像123 millions
一样显示它。
在视图中显示十进制值时,有没有什么方法可以有这样的规则,而不必像这样写?
<td align="right">
@((item.Amount / 1000).ToString("### ###")) k€
</td>
<td align="right">
@((item.Ponderation * 100).ToString("f0")) %
</td>
使用 [DisplayFormat] 属性装饰您的视图模型 属性 并指定所需的格式:
[DisplayFormat(DataFormatString = "{0:N}", ApplyFormatInEditMode = true)]
public decimal Testing { get; set; }
然后在您看来:
@Html.DisplayFor(x => x.Testing)
我正在寻找一种在我的视图中正确格式化和显示小数值的方法。
例如:123456789,9876
应该是123 456 789,99
。
有时我想像123 millions
一样显示它。
在视图中显示十进制值时,有没有什么方法可以有这样的规则,而不必像这样写?
<td align="right">
@((item.Amount / 1000).ToString("### ###")) k€
</td>
<td align="right">
@((item.Ponderation * 100).ToString("f0")) %
</td>
使用 [DisplayFormat] 属性装饰您的视图模型 属性 并指定所需的格式:
[DisplayFormat(DataFormatString = "{0:N}", ApplyFormatInEditMode = true)]
public decimal Testing { get; set; }
然后在您看来:
@Html.DisplayFor(x => x.Testing)