Thank you so much for the help, folks. That turned out to be weird, but
correct. Rounding off to 4 decimal point places solved the problem quite
nicely.

        -- jon



-----Original Message-----
From: Daniel Clark [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 27, 2004 3:16 PM
To: jon roig
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] Math weirdness with doubles...


Looks like the Doubles are not exactly zero.  Must be some precision
points not displaying.


> Ok... It's Friday and maybe my brain is dead, but I'm having a weird 
> problem with some basic math.
>
> Here's a little snippet of the code I'm working with:
>
> ---------------------------
> echo "<p>Current:$currentAmount:".gettype($currentAmount)." - 
> Paid:$paidAmount:".gettype($paidAmount)."</p>";
>
> $currentAmount = $currentAmount-$paidAmount;
> echo "<p>Final Current: $currentAmount";
> -----------------
>
> Straightforward... Yeah?
>
> Here's a sample of the output:
> Current:97.6:double - Paid:97.6:double
> Final Current: 1.42108547152E-014
>
> Now if both $currentAmount and $paidAmount are doubles, subtracting 
> them should yield a zero, shouldn't it?
>
>       -- jon
>
> -------------------
> jon roig
> web developer
> email: [EMAIL PROTECTED]
> phone: 888.230.7557
>
> ---


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 2/20/2004
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to