How to Print Leading Zeroes for a Number in C# ?

The Leading Zeroes for a number can be printed using the format string “D” in .NET . Below is a sample code snippet that demonstrates printing of 3 leading zeroes for a number 5 digit number in C#.

How to Print Leading Zeroes for a Number in C# ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AbundantcodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            // How to Print Leading Zeroes for a Number in C# ?
            int Input = 87654;
            Console.WriteLine(Input.ToString("D8", System.Globalization.CultureInfo.InvariantCulture));
            Console.ReadLine();
        }
    }
    
}
1