I have a column with only one column ‘id’. The create statement of the table is:
CREATE TABLE `test` (
`id` float default NULL
);
The value present in the table is:
id
-----
8.075
When I execute the query:
SELECT ROUND(id, 2) FROM test;
I am getting result ‘8.07’.
But when I simply execute the query:
SELECT ROUND(8.075,2);
I am getting value of ‘8.08’.
What can be done to get the consistent result in both the cases?
The demo of these query can be viewed here.
The result of a round depends on the implicit type of the literal
8.075.The floating point number
8.075is represented internally as the closest possible float, which is8.07499999999999928946, which rounds to 2 places as8.07.If the literal
8.075is being interpreted as a decimal, then the ’round-half-even’ rule is probably being applied. I’d look it up but MySQL’s website is down right now.