Reputation: 17653
I would like to append 0 before a number if it is single digit. For example it should be 01,02,03... 09, 10, 11, ...
Upvotes: 26
Views: 73088
Reputation: 30398
Old school method from VB6, still works:
Dim yourNumber as Long = 5
Format(yourNumber, "00") ' = "05" '
... just for old time's sake :). Better to use Tim's answer.
Upvotes: 1
Reputation: 460098
Dim yourNumber as Int32 = 5
yourNumber.ToString("D2") '= "05"
Upvotes: 36
Reputation: 5800
Try the following...
Dim varNumber As Integer = 3
Dim number As String = String.Format("{0:0#}", varNumber)
Hope that helps.
Upvotes: 4
Reputation: 2306
if(number < 10){
number = Int32.Parse("0" + number.ToString());
}
I guess that was some c# going on :) but you should get the idea.
Upvotes: -3