Display "0034" instead of "34"
When displaying a number, I want to convert it from an integer to a string with leading zeros. Or something like that.
So I have an integer. Let's say 34. I want that number to be displayed as 0034. How would I accomplish this?
EDIT: I'm doing a countdown timer. I wan the timer to count down like this: 12, 11, 10, 09, 08, 07, 06......instead of 12, 11, 10, 9, 8, 7, 6, etc..... So it needs to be dynamically represented, not just adding two 0's to the string.
Re: Display "0034" instead of "34"
Re: Display "0034" instead of "34"
ah....perfect. Thx :)
:thumb:
Re: Display "0034" instead of "34"
another option is to use just the 'ToString()' method
Code:
int i = 34;
string s1 = i.ToString("0000");
string s2 = i.ToString().PadLeft(4, '0');
They both result in the same
Re: Display "0034" instead of "34"
Yeah, I used the pad left after converting ToString(). Works well for me.