Dropping Leading Zeros

database

I have a form that records a student ID number. Some of those numbers contain a leading zero. When the number gets recorded into the database it drops the leading 0.

The field is set up to only accept numbers. The length of the student ID varies.

I need the field to be recorded and displayed with the leading zero.

Best Answer

If you are always going to have a number of a certain length (say, it will always be 10 characters), then you can just get the length of the number in the database (after it is converted to a string) and then add the appropriate 0's.

However, if this is an arbitrary amount of leading zeros, then you will have to store the content as a string in the database so you can capture the leading zeros.