格式化我的十进制属性的正确数据注释是什么? [英] What is the proper data annotation to format my decimal property?
本文介绍了格式化我的十进制属性的正确数据注释是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有十进制属性的POCO,称为SizeUS.我想使用数据注释来设置视图中小数点的显示格式.我的SizeUS属性在我的视图中仅显示2个小数位,并且我希望它显示4个小数位.什么是正确的数据注释才能完成此任务?
I have a POCO with a decimal property called SizeUS. I would like to use data annotations to format the display of the decimal in a view. My SizeUS property is only displaying 2 decimal places in my view and I want it to display 4 decimal places. What is the proper data annotation to accomplish this ?
[DisplayFormat( ? )]
public decimal SizeUS {get; set;}
推荐答案
[DisplayFormat(DataFormatString="{0:#.####}")]
有关格式和,请参见自定义格式字符串.例如,href ="http://msdn.microsoft.com/zh-cn/library/system.componentmodel.dataannotations.displayformatattribute%28v=vs.110%29.aspx"> DisplayFormatAttribute
See Custom Format Strings for formats and DisplayFormatAttribute
for examples
这篇关于格式化我的十进制属性的正确数据注释是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文