问题
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
andDOUBLE
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