add leading zero

T

tshad

In VB.Net,

How do I take a number such as 99 and convert it to 099?

I have a number from a DataTable named dr.Item(1) (dr being a datarow), that
I need to convert to a string with leading zeros. It needs to be 3 chars
long.

Thanks,

Tom
 
G

Greg Burns

some ideas...

Function ThreeDigit(ByVal x As Integer) As String
Return x.ToString.PadLeft(3, "0"c)
'Return Microsoft.VisualBasic.Right("00" & x.ToString, 3)
End Function

Greg
 
T

tshad

Greg Burns said:
some ideas...

Function ThreeDigit(ByVal x As Integer) As String
Return x.ToString.PadLeft(3, "0"c)
'Return Microsoft.VisualBasic.Right("00" & x.ToString, 3)
End Function

Worked great.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top