note 8225 deleted from function.round by jimw
| From: | jimw@php.net | Date: | Wed, 02 Jan 2002 12:13:47 +0000 |
| Subject: | note 8225 deleted from function.round by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-24254@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 ;)