Jump to content

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


galvin

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.