从mysql float返回错误的值 [英] Wrong value returned from mysql float

查看:87
本文介绍了从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?

推荐答案

如果要存储 exact 值,则可以使用

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

通过 FLOAT 的手册:

By manual of FLOAT:

FLOATDOUBLE类型表示近似数字数据值. MySQL使用四个字节的单精度值

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.

您可以在此处阅读有关浮动的更多信息: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆