Padding with Zeros

BlitzMax Forums/BlitzMax Beginners Area/Padding with Zeros

What is the simplist way to pad a number with leading zeros. The number will be 4 digits.

0001
0015
0256
0009

I know this is easy but for some reason it is eluding me.

something like

Local a:Int=2
Local pad:string=a

While Len(pad$)<4
    pad$="0"+pad$
Wend

Print pad$

or this...

Local a:Int=2

Print Format(a,4)

Function Format:String(n:Int,p:Int)

Local pad$=n

While Len(pad$)<p
	pad$="0"+pad$
Wend

Return pad$

End Function


For k = 0 To 9
	score = Rand(0,1111)
	Print Replace(RSet(score,4)," ","0")
Next


Thanks :)

If you know the maximum number of digits you need in a number then the following is enough (example for 8 digits)...

scoreText$=Right("0000000"+score,8)