Jump to content

Force 2-Digit Output


MinusMyThoughts

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...