How to format an integer with zero-padding in C#

2 Answers

0 votes
using System;

class Program
{
    static void Main()
    {
        int number = 319;

        // Format the number with leading zeros to make it 6 digits
        string formatted = number.ToString("D6");

        Console.WriteLine(formatted);
    }
}


/*
run:

000319

*/

 



answered Jun 18, 2025 by avibootz
0 votes
using System;

class Program
{
    static void Main()
    {
        int number = 319;

        // Format the number with leading zeros to make it 6 digits
        string formatted = string.Format("{0:000000}", number);

        Console.WriteLine(formatted);
    }
}


/*
run:

000319

*/

 



answered Jun 18, 2025 by avibootz

Related questions

4 answers 139 views
1 answer 93 views
1 answer 91 views
1 answer 88 views
1 answer 97 views
1 answer 87 views
1 answer 99 views
...