I have a function written in PHP that calculates account balances by subtracting all payments from all charges.
Unfortunately I have one account that is returning a value of -4.5474735088646E-13 when I subtract 2716 from 2716. I was kind of expecting a 0.
I calculate the value in my function like so
$accountbalance = (float)$totalcharges - (float)$totalpayments;
return $accountbalance;
The secondary issue is that when I format the account balance with two decimal places I end up with -0.00
number_format($accountbalance,2)
weird, or what? What is causing this and how do I prevent it?