使用 DisplayFormat 显示 3 位小数

Use DisplayFormat to show 3 decimal places

我是 .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

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

在我的模型中添加 DisplayFormat 的语法后,我是否需要在我的视图中做任何额外的事情?

这是我当前的观点:

@Html.DisplayFor(Function(modelItem) currentItem.StraightRate)

mStraightRate = Format(value, ##.##.##) 你可以使用英镑符号来表示你想要的货币,你可以简单地放置.. mStraightRate = Format(value,"currency") 还有更多选项,但自定义使用顶部。

使用DisplayFormatAttributeDataFormatString 属性 确定值在 DisplayTemplate

中的显示方式
<Display(name:="Straight Rate")>
<DisplayFormat(DataFormatString:="{0:0.000}")>
Public Property StraighRate() As Decimal