0

We saved a value of 2.01 in a float column in MySQL.

Then, after we applied the avg function, it returned 2.009999990463257

Why is this happening?

Here is the query we are using:

SELECT avg(height)  FROM `students` where class='b1'
mustaccio
  • 18,234
  • 16
  • 48
  • 57
  • floats do not store precise values....short explanation: basically, for the same reason you cannot write 1/3 in decimal; floats can only "write" precise halves, quarters, eights, sixteenths, etc.... _it's a bit more complicated than that, involving exponents etc... but that is the gist of it_ – Uueerdo Apr 19 '16 at 19:19
  • 1
    You may want to read [this](http://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate) – mustaccio Apr 20 '16 at 01:24

0 Answers0