How to format int as string with 2 digits in C#

1 Answer

0 votes
using System;

class Test
{
    static void Main() {
        int n = 9;
        string str = n.ToString("D2");

        Console.WriteLine(str);
        Console.WriteLine(18.ToString("D2"));
        Console.WriteLine(721.ToString("D2"));
    }
}



 
/*
run:

09
18
721
 
*/

 



answered Oct 30, 2022 by avibootz

Related questions

1 answer 123 views
1 answer 113 views
113 views asked Oct 30, 2022 by avibootz
1 answer 167 views
1 answer 84 views
...