At 22:17 20.02.2003, Van Andel, Robbert spoke out and said:
--------------------[snip]--------------------
>How do I round a number to the nearest 10 or even 5.  Say I have a
>number like 12.  Is there an easy way to round that up to 15 or 20?
--------------------[snip]-------------------- 

function round_to($number, $full, $isup=true)
{
        $factor = $number % $full;
        if ($isup) {
                if ($factor) $factor = $full - $factor;
                $result = $number + ($factor ? $factor : 0);
        }
        else
                $result = $number - $factor;
        return $result;
}

$x = 12;
$to = 5;
echo "$x => ", round_to($x, $to), "\n", "$x => ", round_to($x, $to, false);


-- 
   >O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
    ^ http://www.vogelsinger.at/


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

Reply via email to