I have a field in a database and I need for it to always show as 5 digits. However right now there is only like 1,2,3,4,5 in the database. I need those to show up as 00001, 00002, 00003 and so on. Anybody have a clue?
| SitePoint Sponsor |





I have a field in a database and I need for it to always show as 5 digits. However right now there is only like 1,2,3,4,5 in the database. I need those to show up as 00001, 00002, 00003 and so on. Anybody have a clue?
Is this for display only?
If it is upon displaying the data:
But this is for display only do not store the zeros in the database.PHP Code:print str_pad(2, 5, '0', STR_PAD_LEFT);





printf is more common
PHP Code:printf("%05d", $number);





I think str_pad is the better choice. printf uses a percentage sign, which looks a bit like classic ASP tags. That's an unnecessary stress.





Bookmarks