的String.Format在C#不返回修改的int值 [英] String.Format in C# not returning modified int value
本文介绍了的String.Format在C#不返回修改的int值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我特林返回与值内逗号seperators一个int值。
I am tring to return an int value with comma seperators within the value.
12345将返回为12345
12345 would be returned as 12,345
该follwing代码工作:
The follwing code works:
int myInt = 1234567;
MessageBox.Show(string.Format("My number is {0}", myInt.ToString("#,#")));
12345如预期显示。
12,345 is displayed as expected.
而下面的代码确实没有工作,但是从我读什么,应该工作:
While the following code does no work, but from what I am reading, should work:
int myInt = 1234567;
MessageBox.Show(string.Format("My number is {0:#,#}", myInt.ToString()));
12345显示。
12345 is displayed.
你能帮助我理解为什么第二组的代码是不工作?
Can you help me understand why the second set of code is not working?
感谢
推荐答案
您不应该的ToString
格式之前,INT。试试这个:
You shouldn't ToString
the int before the format. Try this:
MessageBox.Show(string.Format("My number is {0:#,#}", myInt));
这篇关于的String.Format在C#不返回修改的int值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文