C#将int型数字转换成3位字符串,不足的时候,前面补0

int aa = 11;
string aastr = aa.ToString("000");
//
string aastr = aa.ToString().PadLeft(3,'0');
//结果:011

int num=2;
//三位,不足左侧补零
string str = string.format("{0:d3}",num);
//结果:002
 
string str1 = string.format("{0}{{1:d4}}","1001",12);
//结果:10010012

 

 

转:https://www.cnblogs.com/jiangyunfeng/p/13355677.html

posted @ 2020-11-12 19:23  黄树强  阅读(3679)  评论(0编辑  收藏  举报