Reputation: 2509
My model contains a decimal column, I have checked inside Controller action it has decimal values like below:
0.69874
0.78562
Strange though, when they appear on web page, they are rounded and they become 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.
Upvotes: 0
Views: 2348
Reputation: 39268
Try adding a Display attribute on the property in question
[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
Upvotes: 1