我需要的是5000 - > 5000.00 如果5000.985 ----> 5000.99
总是应该有两位小数。
这是我的模特课。
[Display(Name = "Price (Rs.)")]
public double price { get; set; }
这是我的cshtml页面(查看)。
<div class="display-label">
@Html.DisplayNameFor(model => model.price)
</div>
答案 0 :(得分:5)
您也可以使用注释执行此操作。
[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
有关详细信息,请参阅this answer
答案 1 :(得分:2)
<div class="display-label">
@Math.Round(model=>model.price, 2)
</div>
你最好使用“十进制”而不是“双重”