问题描述
我有一个展示产品视图模型..但价格是十进制格式,我不希望它在视图格式,应该使用全自动的视图模型格式化。我知道有一个属性displayformat ..有任何人知道渲染视图小数的格式等形式0.00 $?
I have a view model that show a product.. but the price is in decimal format and i dont want to format it in the view, it should be automaticly formatted using the viewmodel. I know there is a property displayformat.. is there anyone that know to to render the decimal in the view in the formatted form such 0.00$ ?
推荐答案
您可以使用DisplayFormat属性像下面显示格式的结果。
you can use DisplayFormat attribute like following to show the formatted result
[DisplayFormat(DataFormatString = "{0:###.###$}")]
public decimal myVal { get; set; }
然后设为myVal(允许值为123.222),将显示为123.222 $
Then myVal(lets value is 123.222), will be displayed as 123.222$
更多关于格式化字符串,
More about formatting strings,http://msdn.microsoft.com/en-us/library/fzeeb5cd.aspx
这篇关于如何显示corretly格式化0.00 $格式的小数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!