Re: Ok, why is this happening...
| From: | John Nichel | Date: | Tue, 19 Jul 2005 17:26:15 +0000 |
| Subject: | Re: Ok, why is this happening... | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-218985@lists.php.net to get a copy of this message | ||
Chris Boget wrote:
There's some freaky math going on there or something. I added a couple of other echos in to see and for some reason it seems to be losing single digit value (subtracting, rounding down, I don't know). $calculatedGross = $originalNet + ( $originalNet * $commissionPct * 0.01 ); echo ( "Gross : " . (int)$calculatedGross ." = ". $originalNet ." + ( ". $originalNet ." * ". $commissionPct ." *.01 )<br />\n" );Chris Boget wrote: <snip>Ok, then that begs the following questions: If I don't cast any of the values, why do they display as being identicle? Additionally, why does every IF check fail in that case?echo "if( $originalNet != $calculatedNet ) = " . ( (int)$originalNet !== (int)$calculatedNet ) . "<br>\n";</snip> Change this to echo out what you're comparing... echo "if( ". (int)$originalNet ." != ". (int)$calculatedNet ." ) = " . ( (int)$originalNet !== (int)$calculatedNet ) . "<br>\n"; That'll show what numbers is actually trying to match.
$calculatedNet = $calculatedGross / ( 1 + ( $commissionPct * 0.01 ));echo ( "Net : " . (int)$calculatedNet." = " . (int)$calculatedGross . " / ( 1 + ( " . $commissionPct . " * .01 ) )<br />\n" ); -- John C. Nichel ÜberGeek KegWorks.com 716.856.9675 john@kegworks.com