$total_cost and $amount_paid value is 2028.36 as shown in the bottom right screenshot
// values are from database. both are type decimal 15,2
$balance = ($total_cost - $amount_paid);
the result is 2.2737367544323E-13
The result should be 0. I tried converting both to float. still doesn't work
check screenshot below. I tried printing the value, the result shown in the bottom right corner.
Solved
I did the calculation in the database level instead.
$this->db->select('(SUM(ItemCost * OrderQty) - OrderAmountPaid) - Discount as Balance');