1. Junior Member
Join Date
Dec 1969
Posts
25

I&#039;m trying to output data from a database with leading zeros if applicable. The function formatnumber doesn&#039;t seem to be helping out.<BR><BR>Essentially, I&#039;ve tried this:<BR><BR>&#060;%<BR>dim num<BR>num = 00000582<BR>response.write(formatnumber(num, 0, -1, 0, 0))<BR>%&#062;<BR><BR>As output, I would get 582. Any ideas on what else I can do?<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
1,843

I&#039;ve had the same problem before. My solution was to make it a text field in the DB.

3. Member
Join Date
Dec 1969
Posts
89

Well, if you always want an 8 digit number, you could check the string length and make up the rest with leading zeroes...? Bit of a kludge, I know... i&#039;ll take a peep at something I did a while back and get back to you in a min.

4. Senior Member
Join Date
Dec 1969
Posts
11,247

num = right("000000000" & rs("number"), 8)

5. Member
Join Date
Dec 1969
Posts
89

## That's the fella...

Perfick :) I had this OTT contrivance:<BR><BR>&#060;%<BR>Dim num<BR>num = 00000456<BR>i = 8 - Len(num)<BR><BR>While i &#060;&#062; 0<BR> num = CStr(num)<BR> num = "0" + num<BR> i = i - 1<BR>Wend<BR><BR>Response.Write(num)<BR>%&#062;

6. Junior Member
Join Date
Dec 1969
Posts
25

If I make it a text field, is it still possible to add to it? I&#039;ll also need to be incrementing it by 1 each time I process the number.

7. Member
Join Date
Dec 1969
Posts
89

Well, do all calculations as normal first (use CInt(num) to make sure it&#039;s a number), then wring it through a textaliser (CStr(num)) and add on the leading zeros.

8. Junior Member
Join Date
Dec 1969
Posts
25

## Thanks for the help....

It seems like a bit of a roundabout way of doing things, but hey, whatever works... <BR>Does anyone else find it odd that one has to go to this much trouble just to print leading zero(s)?

9. Senior Member
Join Date
Dec 1969
Posts
1,843

## Of course that will only work

if you always want the number to be 8 digits. <BR><BR>then again, the biggest reason for leading zeros is to make a standard length, so they will probably all need to be the same length.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•