Pad a number with starting zero in .Net

Alex picture Alex · Jan 28, 2009 · Viewed 46.7k times · Source

I have a requirement to pad all single digits numbers with a starting zero. Can some one please suggest the best method? (ex 1 -> 01, 2 -> 02, etc)

Answer

Rockcoder picture Rockcoder · Jan 28, 2009
number.ToString().PadLeft(2, '0')