RE: [PHP] Round to the nearest X

From: Date: Thu, 28 Apr 2005 21:45:04 +0000
Subject: RE: [PHP] Round to the nearest X
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-214155@lists.php.net to get a copy of this message
> 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. > 37678 + 500 - (37678 % 500) Jared

« previous php.general (#214155) next »