Wrong value returned from mysql float

此生再无相见时 提交于 2019-12-10 11:49:02

问题


I have a table with high precision value, stored as Float. When I query the table for that value it returns rounded off value, rounded to 1st digit. But when I run the below query I am getting the value that I have stored,

SELECT MY_FLOAT_COL*1 FROM MY_TABLE;

What's going on inside Mysql?


回答1:


If you want to store exact values, you'd use the DECIMAL data types.

By manual of FLOAT:

The FLOAT and DOUBLE types represent approximate numeric data values. MySQL uses four bytes for single-precision values

The thing to mention here is approximation.

You can read more on floats here: http://dev.mysql.com/doc/internals/en/floating-point-types.html



来源:https://stackoverflow.com/questions/38997372/wrong-value-returned-from-mysql-float

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!