Math weirdness with doubles...

From: Date: Fri, 27 Feb 2004 22:09:20 +0000
Subject: Math weirdness with doubles...
Groups: php.general 
Request: Send a blank email to php-general+get-179031@lists.php.net to get a copy of this message
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: jon@trafficdesigns.com 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

« previous php.general (#179031) next »