vb.net 使用 DisplayFormat 显示 3 个小数位
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28222288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use DisplayFormat to show 3 decimal places
提问by user2816567
I am a newbie to .NET. I cannot figure out the correct syntax to show three decimal places in my view.
我是 .NET 的新手。我无法弄清楚在我的视图中显示三位小数的正确语法。
In my model I currently have:
在我的模型中,我目前有:
<<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
I know I need to use the DisplayFormat in my model, but I cannot figure out the syntax that will make it work.
我知道我需要在我的模型中使用 DisplayFormat,但我无法弄清楚使其工作的语法。
Do I need to do anything additional in my View after I add the syntax for the DisplayFormat in my model?
在我的模型中添加 DisplayFormat 的语法后,我是否需要在我的视图中执行任何其他操作?
Here is what I have in my current view:
以下是我目前的看法:
@Html.DisplayFor(Function(modelItem) currentItem.StraightRate)
回答by
Use the DisplayFormatAttribute. The DataFormatStringproperty determines how the value is displayed in a DisplayTemplate
使用DisplayFormatAttribute. 该DataFormatString属性决定了值如何显示在DisplayTemplate
<Display(name:="Straight Rate")>
<DisplayFormat(DataFormatString:="{0:0.000}")>
Public Property StraighRate() As Decimal
回答by Wiz12
mStraightRate = Format(value, ##.##.##)you can use the Pound signs how you wish for currency you can simply put..
mStraightRate = Format(value,"currency")there are more options but for custom use the top.
mStraightRate = Format(value, ##.##.##)你可以使用英镑符号你想要的货币,你可以简单地放置..
mStraightRate = Format(value,"currency")有更多的选择,但对于自定义使用顶部。

