How can I format a number into a string with leading zeros? September 28, 2022 by Tarik Rather simple: Key = i.ToString("D2"); D stands for “decimal number”, 2 for the number of digits to print.