RE: [PHP] Math weirdness with doubles...

From: Date: Fri, 27 Feb 2004 22:29:25 +0000
Subject: RE: [PHP] Math weirdness with doubles...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-179035@lists.php.net to get a copy of this message
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:dclark@nwlink.com] Sent: Friday, February 27, 2004 3:16 PM To: jon roig Cc: php-general@lists.php.net 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: 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 (#179035) next »