从mysql float返回错误的值 [英] Wrong value returned from mysql float
问题描述
我有一个高精度值表,存储为Float
.当我在表中查询该值时,它将返回四舍五入后的值,四舍五入到第一位.但是当我运行下面的查询时,我得到的是我存储的值,
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;
Mysql内部发生了什么事?
What's going on inside Mysql?
推荐答案
If you want to store exact values, you'd use the DECIMAL
data types.
通过 FLOAT
的手册:
By manual of FLOAT
:
FLOAT
和DOUBLE
类型表示近似数字数据值. MySQL使用四个字节的单精度值
The
FLOAT
andDOUBLE
types represent approximate numeric data values. MySQL uses four bytes for single-precision values
这里要提到的是 近似值 .
The thing to mention here is approximation.
您可以在此处阅读有关浮动的更多信息: http://dev.mysql.com/doc/internals/en/floating-point-types.html
You can read more on floats here: http://dev.mysql.com/doc/internals/en/floating-point-types.html
这篇关于从mysql float返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!