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 /
> 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.
>
On 4/28/05, Greg Donald <[EMAIL PROTECTED]> wrote:
> do {
> $num++;
> } while( $num % 500 );
Actually that fails for the base number 500. This works for everything:
#!/usr/bin/php
> ./round.php
0
> ./round.php 499
500
> ./round.php 500
500
> ./round.php 501
1000
--
Greg Donald
Zend C
I think the formula you are looking for is something like this:
round( y/x, 0) * x
With y being your number and x being the nearest increment number to
round to.
On Apr 28, 2005, at 4:10 PM, Chris Boget wrote:
I realize this is a dumb question but I just can't come
up with an equation that will d
On 4/28/05, Chris Boget <[EMAIL PROTECTED]> 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
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.
I tried using
y
6 matches
Mail list logo