使用DisplayFormat显示3个小数位

use*_*567 2 vb.net asp.net-mvc displayformat

我是.NET的新手。我无法弄清楚在我的视图中显示三位小数的正确语法。

在我的模型中,我目前有:

&lt;<Display(name:="Straight Rate")>
Public Property StraighRate() As Decimal
    Get
        Return mStraightRate
    End Get
    Set(ByVal value As Decimal)
        mStraightRate = value
    End Set
End Property
Run Code Online (Sandbox Code Playgroud)

我知道我需要在模型中使用DisplayFormat,但是我无法弄清楚将使其工作的语法。

在模型中添加DisplayFormat的语法后,是否需要在视图中执行其他任何操作?

这是我目前的观点:

@Html.DisplayFor(Function(modelItem) currentItem.StraightRate)
Run Code Online (Sandbox Code Playgroud)

小智 6

使用DisplayFormatAttribute。该DataFormatString属性确定该值如何显示在DisplayTemplate

<Display(name:="Straight Rate")>
<DisplayFormat(DataFormatString:="{0:0.000}")>
Public Property StraighRate() As Decimal
Run Code Online (Sandbox Code Playgroud)