MySQL round weird bug

前端 未结 2 1217
轮回少年
轮回少年 2020-12-11 18:43

I\'m facing a really weird ¿bug? on mysql+php right now. Is a simple select, in the following example i\'m using multiple fields to try to explain my problem:

2条回答
  •  时光说笑
    2020-12-11 19:21

    The problem is how the DOUBLE and FLOAT values are stored.

    It is possible (and probable) that values like 11.5 or 22.475 coul be stored in approximated values like 11.499999999999~ or 22.475000000000000001 thus some calculations or roundings could lead to incorrect results.

    It is always better to store float values into a DECIMAL coulmn type where the value is stored exactly with all the decimal digits and is not approximated.

提交回复
热议问题