galvin Posted January 4, 2010 Share Posted January 4, 2010 How do I say the following plain English in PHP... If $number is exactly 1 digit long, then append two zeroes to the end it In other words, if $number = 8, then I would want this new code to turn it into 800 I realize I could write ... if ($number == { $number = 800; } But in my code, $number could be anything from 0-9 (and I will use the answer to do other code where I have 2 digit numbers and need to append just one zero to those numbers, but I'm sure I can figure this part out once I know how to do the first part). So Im just hoping there is one simple bit of code that will do that first part (i.e.append two zeroes to a number if it is exactly one digit long). Thanks, Greg Quote Link to comment https://forums.phpfreaks.com/topic/187069-code-to-append-two-zeroes-to-a-number-if-it-is-only-one-digit-long/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 4, 2010 Share Posted January 4, 2010 use str_pad Quote Link to comment https://forums.phpfreaks.com/topic/187069-code-to-append-two-zeroes-to-a-number-if-it-is-only-one-digit-long/#findComment-987863 Share on other sites More sharing options...
galvin Posted January 4, 2010 Author Share Posted January 4, 2010 Perfect thanks! Quote Link to comment https://forums.phpfreaks.com/topic/187069-code-to-append-two-zeroes-to-a-number-if-it-is-only-one-digit-long/#findComment-987897 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.