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 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 +/- (y mod x)
but after I started putting in some test numbers, it didn't always work. For example,
37678 + ( 37678 % 500 )
did not round up to the nearest 500.
Any ideas?
thnx, Chris
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- Brent Baisley Systems Architect Landover Associates, Inc. Search & Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php