I was experimenting with mysql, and made a query to compare two different fields using the GRATEST()
function.
My query looks like this:
SELECT
id,
float1,
float2,
GREATEST(
IFNULL(float1, 0),
IFNULL(float2, 0)
) AS gtst
FROM `test`
Float1 and 2 are UNSIGNED FLOAT, with NULL as default value. Server version: 5.1.73-1-log, client: 5.0.8-dev, PHP extension: mysqli.
Running the above command gives me strange values like this:
| id | float1 | float2 | gtst |
|-----|--------|--------|------------------|
| 872 | 348.5 | 348.58 | 348.579986572266 |
I know that MySQL handles floating point values strangely, as it is described in this article, but it's unclear to me where are these extra digits coming from?
A single comparison shouldn't alter the supplied values, right? There's no mathematical equations here where rounding errors could come into play, so what could be wrong?
Thanks in advance!