int value under 10 convert to string two digit number Ask Question

int value under 10 convert to string two digit number Ask Question
string strI;   

for (int i = 1; i < 100; i++)
    strI = i.ToString();

in here, if i = 1 then ToString yields "1"

But I want to get "01" or "001"

It looks quite easy, but there's only article about

datetime.ToString("yyyy-MM-dd")`

ベストアンサー1

i.ToString("00")

or

i.ToString("000")

depending on what you want

Look at the MSDN article on custom numeric format strings for more options: http://msdn.microsoft.com/en-us/library/0c899ak8(VS.71).aspx

おすすめ記事