Re: [PHP] Round to the nearest X - SOLVED

2005-04-29 Thread Chris Boget
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 /

RE: [PHP] Round to the nearest X

2005-04-28 Thread Jared Williams
> 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. >

Re: [PHP] Round to the nearest X

2005-04-28 Thread Greg Donald
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

Re: [PHP] Round to the nearest X

2005-04-28 Thread Brent Baisley
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

Re: [PHP] Round to the nearest X

2005-04-28 Thread Greg Donald
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

[PHP] Round to the nearest X

2005-04-28 Thread Chris Boget
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