project3 Posted February 9, 2008 Share Posted February 9, 2008 I have a number that I want to make sure the leading zero doesn't get striped before adding to my db. 020808 it will always be six digits. thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/90154-number-format/ Share on other sites More sharing options...
kts Posted February 9, 2008 Share Posted February 9, 2008 Put it in a string? Quote Link to comment https://forums.phpfreaks.com/topic/90154-number-format/#findComment-462296 Share on other sites More sharing options...
project3 Posted February 10, 2008 Author Share Posted February 10, 2008 That doesn't work for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/90154-number-format/#findComment-463411 Share on other sites More sharing options...
sasa Posted February 10, 2008 Share Posted February 10, 2008 try <?php $number = 2808; $string = sprintf('%06d',$number); echo $string; ?> Quote Link to comment https://forums.phpfreaks.com/topic/90154-number-format/#findComment-463429 Share on other sites More sharing options...
project3 Posted February 10, 2008 Author Share Posted February 10, 2008 try <?php $number = 2808; $string = sprintf('%06d',$number); echo $string; ?> Thanks thats perfect. Quote Link to comment https://forums.phpfreaks.com/topic/90154-number-format/#findComment-463436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.