[BNM] php rounding bizzarreness
Ali
ali at nubz.com
Thu Mar 9 16:45:59 GMT 2006
have you tried number_format($vat,2);
maybe this rounds differently to round on your version?
both round your example DOWN on my PHP 4.3.11!
subtotal=170.20
VAT=29.785
Total=199.985
Rounded VAT=29.78
Rounded Total=199.98
Formatted VAT=29.78
Formatted Total=199.98
Ali
----- Original Message -----
From: 'Alex' Bridge
To: Brighton New Media
Sent: Thursday, March 09, 2006 3:45 PM
Subject: Re: [BNM] php rounding bizzarreness
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
--
BNM info/subscription/archives: http://www.brightonnewmedia.org/
BNM archive search: http://www.roddis.org/bnm/search.php
BNM Del.icio.us tag: http://del.icio.us/tag/bnm/
BNM Flickr group: http://www.flickr.com/groups/bnm/
BNM powered by http://www.screen-play.net/
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.2.1/277 - Release Date: 08/03/2006
More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service