[英]what decimal value got rounded in Razor view?
My model contains a decimal column, I have checked inside Controller action it has decimal values like below: 我的模型包含一个十进制列,我在Controller操作中检查了它的十进制值,如下所示:
0.69874
0.78562
Strange though, when they appear on web page, they are rounded and they become 0.70
但是奇怪的是,当它们出现在网页上时,它们被四舍五入,变为
0.70
My model class has this property as: 我的模型类具有以下属性:
public virtual decimal Rate { get; set; }
Inside view code is: 内部视图代码为:
<td>@(Html.DisplayFor(m=>row.Rate))</td>
Can you please guide why it is being round automatically and what I should do to stop this, I want to display what ever is real value. 您能指导一下为什么它会自动运行吗?我应该怎么做才能阻止这种情况,我想展示什么才是真正的价值。
Much thanks for your guidance and helping me. 非常感谢您的指导和帮助。
Try adding a Display attribute on the property in question 尝试在相关属性上添加Display属性
[DisplayFormat(DataFormatString = "{0:F3}")]
public virtual decimal Rate { get; set; }
Here are more options for formats http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx 这是格式的更多选项http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.