的String.format整数用于小整数无小数位千位分隔符或0领先 [英] String.Format an integer to use a thousands separator without decimal places or leading 0 for small integers

查看:231
本文介绍了的String.format整数用于小整数无小数位千位分隔符或0领先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

愚蠢的问题,我想,使其出现与1000的分隔符(,),也没有小数位,无格式整数的前导0。

Silly question, I want to format an integer so that it appears with the 1000's separator (,), but also without decimal places and without a leading 0.

我尝试迄今已

String.Format("{0} {1}", 5, 5000);            // 5 5000
String.Format("{0:n} {1:n}", 5, 5000);        // 5.00 5,000.00
String.Format("{0:0,0} {1:0,0}", 5, 5000);    // 05 5,000

输出我追求的是:

The output I'm after is:

5 5,000

有什么明显的是我失踪?

Is there something obvious that I'm missing?

推荐答案

这为我工作。

String.Format("{0:#,0} {1:#,0}", 5, 5000); // 5 5,000

这篇关于的String.format整数用于小整数无小数位千位分隔符或0领先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆