[BNM] php rounding bizzarreness
'Alex' Bridge
alx at dashalx.co.uk
Thu Mar 9 15:45:31 GMT 2006
Alex Farran wrote:
> Well my version of PHP (4.3.7) rounds up:
>
> vat 29.785
> vat_round 29.79
>
> total 199.985
> round_total 199.99
>
> So obviously it's changed. I can't see how the round-to-even rule
> applies to Andy's code though.
>
Errr...good point. That'll teach me to think I know the answer without
looking properly.
Using a different version of PHP is probably the answer though. I just
turned up a comment in the manual which says:
"The bankers' rounding behaviour mentioned in the notes below seems to
have been changed to normaly rounding.
From the comments in http://bugs.php.net/bug.php?id=24142 it was
changed in 4.3.0 but various bugs seem to have been introduced and it
wasn't stable again until 4.3.5 (http://bugs.php.net/bug.php?id=25694)"
So I'd either use 4.2.x or lower (for banker's rounding) or 4.3.5 or up
(for standard rounding).
-alx
More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service