|
-
November 16th, 2009, 03:15 PM
#1
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.
-
November 16th, 2009, 03:24 PM
#2
Re: Display "0034" instead of "34"
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
-
November 16th, 2009, 03:44 PM
#3
Re: Display "0034" instead of "34"
ah....perfect. Thx 
-
November 17th, 2009, 03:07 AM
#4
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
-
November 17th, 2009, 02:00 PM
#5
Re: Display "0034" instead of "34"
Yeah, I used the pad left after converting ToString(). Works well for me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|