Hi, 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)
+16
A:
I'd call .ToString on the numbers, providing a format string which requires two digits, as below:
int number = 1;
string paddedNumber = number.ToString("00");
bdukes
2009-01-28 21:31:07
Awesome, thank you!
Alex
2009-01-28 21:45:11
+1
A:
Assuming you're just outputing these values, not storing them
int number = 1;
Console.Writeline("{0:00}", number);
Here's a useful resource for all formats supported by .Net.
MrTelly
2009-01-29 01:21:09