Question:

ASP (classic) Question?

by  |  earlier

0 LIKES UnLike

hello. I want to write 250 as 0000250

I always want the number 7 digits.

how can I do that?

for example:

convert("250") will give me this result:

0000250

 Tags:

   Report

2 ANSWERS


  1. Function ZeroPad(InputVal, OutputWidth)

       Dim PadBuf

       If Len(CStr(InputVal)) > OutputWidth Then

          ZeroPad = CStr(InputVal)

          Exit Function

       End If

       PadBuf = "0000000000"

       While OutputWidth > Len(PadBuf)

          PadBuf = PadBuf & PadBuf

       Wend

       ZeroPad = Right(PadBuf & InputVal, OutputWidth)

    End Function

    ZeroPad(999, 7)

    output: "0000999"

    ZeroPad(51, 4)

    output: "0051"

    ZeroPad(123456789, 7)

    output: "123456789"


  2. There is no single command in VBscript that can do this so you can use:

    right ("000000" + cstr(250), 7)

    This will add zeros to the start of the number so it always has 7 digits.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.