//flex table opened by JP

Click to See Complete Forum and Search --> : leading zeros


doowle
09-16-2002, 02:03 AM
Can anyone tell me a script for adding leading zeros?

I have an asp page that pulls a database number, "Total" and prints it to an output page. The actual digits of Total might be 1 or 2 or 3, but the output must always be 3...

i.e, if total is 5, my output be 005
it total is 15, my output must be 015
if total is 115, my output must be 115

anyone?

Quandary
09-16-2002, 10:56 AM
This is off of the top of my head, so the syntax may be a little off, but why not try something like the following...

(in ASP, using VBScript)

<%
sub threedigits(input)
if input < 10 then
input = "00" & input
else if input < 100
input = "0" & input
end if
end sub
%>


This should work as long as your input is numeric only.

-- Quandary

AltatemTC
09-17-2002, 02:32 PM
How about

input = Right("000" & input, 3)

?

doowle
09-17-2002, 07:40 PM
Works perfectly, AltatemTC! Thanks!

:)