Re: Round to the nearest X
| From: | Greg Donald | Date: | Thu, 28 Apr 2005 21:02:45 +0000 |
| Subject: | Re: Round to the nearest X | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-214154@lists.php.net to get a copy of this message | ||
On 4/28/05, Greg Donald <destiney@gmail.com> wrote:
> do {
> $num++;
> } while( $num % 500 );
Actually that fails for the base number 500. This works for everything:
#!/usr/bin/php
<?php
$num = isset( $_SERVER[ 'argv' ][ 1 ] )
? $_SERVER[ 'argv' ][ 1 ]
: 0;
if( $num % 500 )
{
do {
$num++;
} while( $num % 500 );
}
echo $num;
?>
> ./round.php
0
> ./round.php 499
500
> ./round.php 500
500
> ./round.php 501
1000
--
Greg Donald
Zend Certified Engineer
http://destiney.com/