Re: Round to the nearest X

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/28/05, Chris Boget <chris.boget@xxxxxxxx> wrote:
> I realize this is a dumb question but I just can't come
> up with an equation that will do this and I don't see an
> internal PHP function (for version 4.3) that will do this...
> Basically I need to come up with an equation/algorithm
> that will round any number up/down to the nearest X.

#!/usr/bin/php
<?php

$num = isset( $_SERVER[ 'argv' ][ 1 ] )
    ? $_SERVER[ 'argv' ][ 1 ]
    : 0;

do {
    $num++;
} while( $num % 500 );
    
echo $num;

?>

> ./round.php 499
500

> ./round.php 501
1000


-- 
Greg Donald
Zend Certified Engineer
http://destiney.com/

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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux