RE: [PHP] What am I doing wrong?

From: Date: Thu, 17 Apr 2003 07:31:01 +0000
Subject: RE: [PHP] What am I doing wrong?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-144233@lists.php.net to get a copy of this message
On 17-Apr-2003 Warren Vail wrote: > Does anyone see what I am doing wrong here? > > <?php > > $monthly = 14.95; > $qtrly = 44.85; > > if($qtrly != 0 && $qtrly != ($monthly * 3)) > echo "Quarterly Incorrect ".$qtrly." ".($monthly * 3); > else echo "Quarterly correct ".$qtrly." ".($monthly * 3); > ?> > > yields the following; > > Quarterly Incorrect 44.85 44.85 > You're comparing floating point numbers for equality. <?php $monthly = 14.95; $qtrly = 44.85; if($qtrly != 0 && $qtrly != ($monthly * 3)) echo "Quarterly Incorrect ".$qtrly." ".($monthly * 3); else echo "Quarterly correct ".$qtrly." ".($monthly * 3); printf('<P>%0.14f<br>%0.14f<P>', $qtrly, ($monthly * 3)); ?> Regards, -- Don Read dread@texas.net -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it.

« previous php.general (#144233) next »