Return to Snippet

Revision: 25717
at April 7, 2010 02:46 by jodm


Initial Code
function roundnum ($num, $nearest)
{
   $ret = 0;
   $mod = $num % $nearest;

   if ($mod >= 0)
     $ret = ( $mod > ( $nearest / 2)) ? $num + ( $nearest - $mod) : $num - $mod;
    else
     $ret = ( $mod > (-$nearest / 2)) ? $num - $mod : $num + ( -$nearest - $mod);
    return $ret;
}

Initial URL

                                

Initial Description

                                

Initial Title
Round Number to Nearest

Initial Tags
number

Initial Language
PHP