当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - string format for numbers or currency?

问题描述:

I need to give comma(,) for every thousends. So I used DataFormatString="${0:#,#}". It is working fine. But when value is 0. It is showing $00. I just want to show only $0.

How can we do that?

网友答案:

Format = "${0:#,0}";

网友答案:
DataFormatString = "{0:C0}"

That will format as a currency with 0 decimal places.

DataFormatString = "{0:N0}"

This will format as a number such as 1,000. If you want decimal places then replace the second 0 with however many numbers you want after the decimal.

For example:

DataFormatString = "{0:N4}"

Would format like 1,000.0000

网友答案:

I know this is an old question, but as I keep forgetting the answer myself, the MSDN reference for all things string formatting is located here;

http://msdn.microsoft.com/en-us/library/26etazsy.aspx

网友答案:

DataFormatString=""... Hope this help:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring%28v=vs.110%29.aspx

分享给朋友:
您可能感兴趣的文章:
随机阅读: