I have a question about a query that I'm running on a MySQL Server (v5.5.50-0+deb8u1).
SELECT 12 - (SELECT qty FROM Table WHERE id = 5213) AS Amount
so Amount value is 12 - 8,5500000000000007 = 3.4499999999999993
But if I run the query:
SELECT qty FROM Table WHERE id = 5213
it returns 8.55 that is the correct number written in the record, so I was expecting that the first querty returned 3.45.
The "qty" column in the table "Table" is a DOUBLE.
How is it possibile? How can I get the right answer from the query? thanks in advance
Well that's just the way floating numbers are.
This statement holds true for many programming languages as well. Some numbers don't even have an exact representation. Here's something from the python manual
So in short generally doing is
float1 = float2
type of comparison is a bad idea but everyone keeps forgetting it.