Jump to content

floating point subtraction error


Recommended Posts

The result you got in the first version is not an error, 5.6843418860808E-14 actually equals -0.64999999999998, it's just written in its exponential form.


Try using the (int) statement twice, like this.


$balance_due = ((int) $salesreceipt_grandtotal) - ((int) $payments_applied);

Link to comment
Share on other sites

Bingo, that works perfectly, thank you!


You're welcome.


Also, I noticed that 5.68...E-14 is not -0.649..., I forgot that in the first code I provided, one of the results was already being converted to an int.

So, for the record, 5.68...E-14 is close to -0.649..., but not equal to it.


Sorry for the confusion.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.