开发者

How to display the number “12” in the format of “0000012”

开发者 https://www.devze.com 2023-02-12 07:14 出处:网络
How to display the number “12” in the format of “0000012” Usi开发者_开发百科ng C#var str = string.Format(\"{0:d7}\", 12);

How to display the number “12” in the format of “0000012” Usi开发者_开发百科ng C#


var str = string.Format("{0:d7}", 12);


var formatted = String.Format("{0:0000000}", 12);

or

Console.WriteLine("{0:0000000}", 12);

I will add that if "12" is a string (it's in double quotes)

var formatted = "12".PadLeft(7, '0');


var a = 12;
var b = a.ToString("D7");


int a = 12;
string b = a.ToString("0000000");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号