Click to See Complete Forum and Search --> : numbers not formatting correctly


jjr0319
07-28-2005, 03:20 PM
i have a field in my Access DB that autonumbers, starting at "0001". it's formated correctly in Access, but when the ASP i made pulls the number, it formats it as just "1". how can i get it to keep the leading 0's? i pasted only the portions of the code that deal with this field below:

Do While Not rs.EOF
lognum= rs("LOG_NUM")

<td align="center" valign="middle" width="5%" class="<%= str_class %>"><b>Action Log:</b> <%= lognum %></td>

thanks in advance for the help.

silverbullet24
07-28-2005, 05:48 PM
i don't think you can do that. number fields in a database don't usually have any leading zero's. you might try converting it to a string right away, i don't know if that will do it or not

<%=Cstr(str_class)%>

buntine
07-28-2005, 09:12 PM
The database will serve it as an integer, thus truncating any leading zero's.

Regards.

Iridium52
07-29-2005, 11:00 PM
If the leading zero's are necessary, you could try something like this:

lognum= rs("LOG_NUM")
lognumlength=len(lognum)
leadingzeros=4-lognumlength

iLoop=0

Do until iLoop = leadingzeros
iLoop=iLoop+1
Response.Write "0"
Loop

Response.Write lognum

Adamal
08-03-2005, 05:01 PM
How about this?

lognum= rs("LOG_NUM")

Response.Write Right("0000" & CStr(lognum), 4)

' or even shorter

Response.Write Right("0000" & lognum, 4)