使用添加了的String.Format数量和逗号 [英] add commas using String.Format for number and
本文介绍了使用添加了的String.Format数量和逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用的String.Format我如何能确保所有的数字有逗号,每3个数字后,
例如:23000 =23000,而0返回0。
Using String.Format how can i ensure all numbers have commas after every 3 digits eg 23000 = "23,000" and that 0 returns "0".
的String.Format({0:N},0); //给出了0.00,我不想。
我不想要任何小数,所有数字将是整数。
String.Format("{0:n}", 0); //gives 0.00 which i dont want. I dont want any decimal places, all numbers will be integers.
推荐答案
您可以做到这一点,我觉得这有点清洁读的意图:
You can do this, which I find a bit cleaner to read the intent of:
String.Format("{0:#,###0}", 0);
例如:
string.Format("{0:#,###0}", 123456789); // 123,456,789
string.Format("{0:#,###0}", 0); // 0
这篇关于使用添加了的String.Format数量和逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文