c# 字符串格式 - 找不到正确的方法

c# string format - cant find the right method

我想printf("%+'10d")一个整数。 找不到 string.Format 的等效语法。 你能帮帮我吗?

printf("%+'10d %+'10d %+'10d", 0, -102048224, 4865284)

会显示:

    +0 -102,048,224 +4,865,284

但是:

string.Format("{0,10:+#;-#;0} {1,10:+#;-#;0} {2,10:+#;-#;0}", 0, -102048224, 4865284)

给出(没有逗号,我不关心 +0 与 0):

     0 -102048224   +4865284

string.Format("{0,10:n0} {1,10:n0} {2,10:n0}", 0, -102048224, 4865284)

给出(最后一个数字没有正号):

     0 -102,048,224  4,865,284

谢谢, -Moshe.

这应该可以解决问题:

string.Format("{0:+#,0.##;-#,0.##}     {1:+#,0.##;-#,0.##}     {2:+#,0.##;-#,0.##}", 0, -102048224, 4865284)

打印:

+0     -102,048,224     +4,865,284

数字右对齐:(13随意,选择适合自己的)

string.Format("{0,13:+#,0.##;-#,0.##}\n{1,13:+#,0.##;-#,0.##}\n{2,13:+#,0.##;-#,0.##}", 0, -102048224, 4865284);

打印:

           +0
 -102,048,224
   +4,865,284