I just hit an odd issue. I have the following tables in MySQL:
table:deposits
user_id amount
1 0.50
table:withdrawls
user_id amount
1 0.01
1 0.01
1 0.01
To get the balance, I run this:
SELECT (IFNULL((SELECT sum(amount) FROM deposits WHERE user_id = 1),0) - IFNULL((SELECT sum(amount) FROM withdrawls WHERE user_id = 1),0) ) as balance
I then return it as
return (float) $row['balance']
For some weird reason, the result is float(0.47000000067055). Does anyone know why there is bizarre rounding?