Thank you for everyone's suggestions.  Using them
(and a few other things I've found elsewhere), I've
come up with the following function:

function roundToNearest( $number, $toNearest = 5 ) {

  $retval = 0;

  $mod = $number % $toNearest;

  if( $mod >= 0 ) {
    $retval = ( $mod > ( $toNearest / 2 )) ? $number + ( $toNearest - $mod )
: $number - $mod;

  } else {
    $retval = ( $mod > ( -$toNearest / 2 )) ? $number - $mod : $number +
( -$toNearest - $mod );

  }
  return $retval;

} // end function round();

that works with positive and negative numbers and seems
to work with every test I threw at it.

Thanks again for everyone's help!

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to