By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,581 Members | 1,966 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,581 IT Pros & Developers. It's quick & easy.

How to get leading zeros while conversion from integer to string

Jugmike
P: 4
Hi
I want to have a format while conversion from integer to string i want that string has 5 digits and if integer has 3 digits only then it is represented like 00122. There is programming which i can do to achieve the same but just wanted to know if .net provides for the same
Thanks
Jugmike
Mar 27 '07 #1
Share this Question
Share on Google+
1 Reply


SammyB
Expert 100+
P: 807
Hi
I want to have a format while conversion from integer to string i want that string has 5 digits and if integer has 3 digits only then it is represented like 00122. There is programming which i can do to achieve the same but just wanted to know if .net provides for the same
Thanks
Jugmike
Yep, remember that in DotNet, everything is an object, so if you have an integer variable, n, then n.ToString("00000") gives you "00122".
Expand|Select|Wrap|Line Numbers
  1. Dim n As Integer = 122
  2. MsgBox(n.ToString("00000"))
Mar 27 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.