PHP Round Up to Nearest Hundred Function
Here is a PHP Quickie!
NEW:
function roundNearestHundredUp($number)
{
return ceil( $number / 100 ) * 100;
}OLD:
function roundNearestHundredUp($number){
$round = round($number, -2);
if($number > $round){ $round = $round + 100;}
return $round;
}
You can achieve the same result in one line:
function roundNearestHundredUp($number)
{
return ceil( $number / 100 ) * 100;
}
Thanks Dan! Nice way to NOT over complicate things. I am updating the post right now.
changing:
function roundNearestHundredUp($number){$round = round($number, -2);
if($number > $round){ $round = $round + 100;}
return $round;
}
To:
function roundNearestHundredUp($number){
return ceil( $number / 100 ) * 100;
}