如何正确显示小数?

时间:2016-05-30 09:22:50

标签: c# asp.net-mvc razor view decimal

我正在寻找一种在我的视图中正确格式化并显示小数值的方法。

例如:123456789,9876应为123 456 789,99

有时我想像123 millions一样显示它。

在View中显示十进制值而不必像这样编写时,有没有办法有这样的规则?

<td align="right">
    @((item.Amount / 1000).ToString("### ###")) k&euro;
</td>
<td align="right">
    @((item.Ponderation * 100).ToString("f0")) &#37;
</td>

1 个答案:

答案 0 :(得分:1)

使用[DisplayFormat]属性装饰视图模型属性,并指定所需的格式:

[DisplayFormat(DataFormatString = "{0:N}", ApplyFormatInEditMode = true)]
public decimal Testing { get; set; }

然后在你看来:

@Html.DisplayFor(x => x.Testing)
相关问题