is the bankers' round() algorithm implemented well?
| From: | Ron Korving | Date: | Mon, 07 Feb 2005 20:39:20 +0000 |
| Subject: | is the bankers' round() algorithm implemented well? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-14698@lists.php.net to get a copy of this message | ||
I understood that round() is using the so called Bankers' round algorithm.
But I notice it's inconsistent. The banker's algorithm is magically
activated only for numbers beyond 2047.0. Before 2047, the "classic"
5-is-rounded-up method is used.
5 is rounded up for:
round(9.005, 2) gives 9.01
round(9.015, 2) gives 9.02
round(9.025, 2) gives 9.03
round(9.035, 2) gives 9.04
round(2047.005, 2) gives 2047.01
round(2047.015, 2) gives 2047.02
round(2047.025, 2) gives 2047.03
round(2047.035, 2) gives 2047.04
bankers' rounding:
round(2048.005, 2) gives 2048.01
round(2048.015, 2) gives 2048.01
round(30000.005, 2) gives 30000.01
round(30000.015, 2) gives 30000.01
This can't be intentional, can it? Someone tell me if this is a bug or a
feature please.
Ron