Reputation: 979
I am performing a query that will subtract a balance from a row by 1. However, after the query will run successfully once, the math becomes off.
If I subtract 0.1 from 1.0, it gives me 0.9. However, the next time I subtract 0.1, I get 0.8000000000000001. Here is the query I'm using:
UPDATE ACCOUNTS SET BALANCE=BALANCE-$amt WHERE ID=$user_id
$amt is 0.1 and $user_id is 1, in this case.
Why does the math change after a successful query? Thanks!
Upvotes: 1
Views: 76
Reputation: 979
Thanks to @tintran I figured out that it had to do with the LENGTH/VALUE part of being a decimal. I changed it to (10,8). 8 is because I am dealing in Bitcoin and 8 decimal places is the max I could go.
Thanks everyone!
Upvotes: 1
Reputation: 3484
UPDATE ACCOUNTS SET BALANCE=ROUND((BALANCE-$amt),2) WHERE ID=$user_id
try this....
Upvotes: 0