Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

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

like image 455
saran Avatar asked Feb 22 '11 09:02

saran


2 Answers

var str = string.Format("{0:d7}", 12);
like image 101
Evgeny Gavrin Avatar answered Oct 05 '22 23:10

Evgeny Gavrin


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');
like image 36
xanatos Avatar answered Oct 06 '22 00:10

xanatos