Re: currency rounding issues
| From: | Michael Davey | Date: | Thu, 06 Jun 2002 01:48:43 +0000 |
| Subject: | Re: currency rounding issues | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-100848@lists.php.net to get a copy of this message | ||
I have found that the best way to work with currencies is to avoid using any
type of floating point math.
If you multiply your start amount by 100, then perform your calculations as
integers and then divide by 100 again at the end, it should work out OK...
(Heh, at least it has worked for me when doing tax calcs and stuff - who
know what you are doing?!?!?!?)
Mikey
"Paul Berg" <paul@spondo.com> wrote in message
news:20020606010121.24069.qmail@pb1.pair.com...
> Hi,
>
> I am putting together an app that involves the adding together of rounded
> numbers and displaying in a currency format.
> The round() function is causing errors of 1 cent to appear after addition.
> Does anyone know of any routines that might assist?
>
> Thanks in advance...
> Paul
>
>