note 26761 added to function.round
| From: | dpatton at no dot spam dot confluence dot org | Date: | Tue, 12 Nov 2002 00:54:14 +0000 |
| Subject: | note 26761 added to function.round | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39359@lists.php.net to get a copy of this message | ||
The round() function doesn't "work properly" for some values.
Here's an example from a posting on the mailing list:
http://groups.google.com/groups
?selm=aevg53%2420ru%241%40FreeBSD.csie.NCTU.edu.tw
Matthew Clark wrote:
Seeing as the mathematically correct way to round numbers is to round down
to n for n-1<=m<=n.5 and up to n+1 for n.5<m<n+1, I wonder why the PHP
round() function couldn't include a little 'fuzz' to handle the rounding
problems we encounter due to floating point representation in the hardware?
It could even be a configurable option - but it would save writing a wrapper...
Matthew,
I can't agree with you more.
I really don't understand the point of php having a round function which
gives the wrong answer on even very simple decimals
e.g. round(0.35,1) returns 0.3.
[snip]
Regards,
George
--
http://www.php.net/manual/en/function.round.php
http://master.php.net/manage/user-notes.php?action=edit+26761
http://master.php.net/manage/user-notes.php?action=delete+26761
http://master.php.net/manage/user-notes.php?action=reject+26761