How can I format a number into a string with leading zeros?

Rather simple:

Key = i.ToString("D2");

D stands for “decimal number”, 2 for the number of digits to print.

Leave a Comment