Link to home
Start Free TrialLog in
Avatar of pdheady
pdheady

asked on

php function to format number from 1 to 99 to 3 digits

Take any number 1 to 100 and format so there are always 3 digits.

Example:

$numberA = 1;
$numberB = 10
$numberC = 85

Now format each as:

$numberA = 001;
$numberB = 010;
$numberC = 085;

So need function that is smart and can take any number 1-99 and format to 3 digits. So if number happens to 100 or 150 then dont touch number!

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this will do

function format_number($number){
    return substr("000".$number, -3);
}


oops sorry repost, please ignore my post
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial