note 8225 added to round

From: Date: Thu, 31 Aug 2000 18:43:16 +0000
Subject: note 8225 added to round
Groups: php.notes 
Request: Send a blank email to php-notes+get-3803@lists.php.net to get a copy of this message
What about using "floor(x*p+0.5)/p" where p is 10^a with a is the precision of the "ordinary round" you want? With a=1 this gives the usual round with "floor(x+0.5)". Note that it's usable for a below 0, too, but then better write: "floor(x/p+0.5)*p". With p=1000 the latter rounds 1500 up to 2000. Excercise for the reader: Write a general rounding function which allows another numerical base instead of 10, like 2, 3 or 7 ;) http://www.php.net/manual/function.round.php

« previous php.notes (#3803) next »