Re: when 1+1 is not equal to 2... STRANGE float behavior

From: Date: Mon, 21 Jan 2002 19:21:34 +0000
Subject: Re: when 1+1 is not equal to 2... STRANGE float behavior
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-81419@lists.php.net to get a copy of this message
Answered my own question... rounding using the "round" function to two decimal places did the trick: <? $contract_amount = 9961.00; $bill1 = .95; $bill2 = .05; $billable_this_month += ($contract_amount * $bill1); $paid_to_date += ($contract_amount * $bill2); $paid_to_date = round($paid_to_date,2); $billable_this_month = round($billable_this_month,2); $contract_amount = round($contract_amount,2); echo "conditional: if(($paid_to_date + $billable_this_month) >= $contract_amount)\n<br>\n"; if(($paid_to_date + $billable_this_month) >= $contract_amount) { echo "true"; } else { echo "false"; } ?> now outputs "true". :-) -- ------------------------- Marc Swanson MSwanson Consulting Phone: (603)868-1721 Fax: (603)868-1730 Mobile: (603)512-1267 mswanson@mswanson.com http://www.mswanson.com -------------------------

« previous php.general (#81419) next »