MinusMyThoughts Posted December 13, 2006 Share Posted December 13, 2006 my question, hopefully, is slap-your-forehead easy......how do i force the output of a variable containing '0' to output '00'?...thanks!love,jason Link to comment Share on other sites More sharing options...
jesh Posted December 13, 2006 Share Posted December 13, 2006 My PHP is so rusty, there's probably a function built in that does this, but here's what a javascript function would look like: function pad(number){ if(number < 10) { return "0" + number; } else { return number; }}document.write(pad(5)); // writes "05"document.write(pad(12)); // writes "12" EDIT: Hmm, this may be what you are looking for: http://www.php.net/str_pad $input = "5";echo str_pad($input, 2, "0", STR_PAD_LEFT); Link to comment Share on other sites More sharing options...
justsomeguy Posted December 13, 2006 Share Posted December 13, 2006 How about this:http://us2.php.net/manual/en/function.round.phpround ($num, -2);Never mind, that doesn't work like I thought it would. str_pad is probably the best way. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now