How to display the number “12” in the format of “0000012”
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");
精彩评论