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$ ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
you can use DisplayFormat attribute like following to show the formatted result
[DisplayFormat(DataFormatString = "{0:###.###$}")]
public decimal myVal { get; set; }
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