PHP

PHP Round Up to Nearest Hundred Function

TAGs: 2 Comment

Posted By: eligeske on in PHP

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;
}

2 Responses to "PHP Round Up to Nearest Hundred Function"

"SHARING IS CARING"
  1. Dan says:

    You can achieve the same result in one line:

    function roundNearestHundredUp($number)
    {
    return ceil( $number / 100 ) * 100;
    }

  2. eligeske says:

    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;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Learning DHTMLX Suite UI

Learn the foundation of the DHTMLX Suite quickly while building a single page application with multiple components in harmony.

Popular post