使用“显示格式”显示 3 位小数



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

使用DisplayFormatAttribute .DataFormatString 属性确定值在DisplayTemplate中的显示方式

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

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

最新更新