Jump to content

Code to append two zeroes to a number if it is only one digit long


Recommended Posts

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.