My brain hurts--It just doesn't add up
I just spent a good part of the last 2 hours trying to debug a calculation problem on a fairly simple report. Basically, it lists "open-bills" from an e-commerce application. The logic sorts through records to find any orders where the Total minus the Payment plus any Credits does not equal zero and displays.
Well... the complaint was that orders were appearing on the open-bills report which didn't belong. I quickly verified this, however, something didn't quite make sense.
Although this isn't the actual code, the following calculation is consistently returning "3.5527136788E-15" instead of zero on ColdFusion version 7.02:
<cfscript>
Balance = 14; //account balance
Payment = 35.94; // payment amount
Credit = 21.94; // credit
// calculate result
Result = ((Balance - Payment) + Credit);
// Result value is "3.5527136788E-15"
writeoutput(Result);
</cfscript>
Changing the values slightly will produce the expected result... however, I noticed changing the Payment and Credit values to 32.95 and 21.95 will produce a negative "3.5527136788E-15".
I've been able to replicate this on 2 different installations of 7.02 so far... It would be great to see if anyone else had any ideas or input about this.
UPDATEI'm not sure if I've identified a ColdFusion bug or not... however, I found that applying some kind of format (numberFormat() or dollarFormat()) to the Result will display the correct value.
The trick is, you need to hack into the mainframe and override the fire walls. Didn't you watch Johnny Mnemonic?