How to get leading zeros while conversion from integer to string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jugmike
    New Member
    • Mar 2007
    • 4

    How to get leading zeros while conversion from integer to string

    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
  • SammyB
    Recognized Expert Contributor
    • Mar 2007
    • 807

    #2
    Originally posted by Jugmike
    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("000 00") gives you "00122".
    Code:
    Dim n As Integer = 122
    MsgBox(n.ToString("00000"))

    Comment

    Working...