Hi
I have a table in MySQL with field type float. the field stores value like 99.99,99.99,99.99
when in php I do "select sum(field) from..."
I get number like 297.98999786377
when it should be 297.97
why? this is not very accurate!
any ideas?
Floating point inaccuracy is to be expected. You could consider using numeric instead of float.
Like LL said, you probably want to use a DECIMAL data type (NUMERIC is treated the same as DECIMAL in MySQL), but if that's not feasible, you could apply the ROUND() function in the query:
SELECT ROUND(SUM(`field`), 2) . . .
changing it to decimal did the trick. thanks