linweiway67 2014-09-01 08:01 采纳率: 0%
浏览 2049

mysql浮点型输出格式问题

drop table if exists d;
create table d(c double) engine=innodb;
insert into d values(1e-15),(1e-16);
select * from d;
在mysql数据库按以上语句建表,输出结果如下:
+-------------------+
| c |
+-------------------+
| 0.000000000000001 |
| 1e-16 |
+-------------------+
为什么1e-15按照正常输出,1e-16输出为1e-16,跪求mysql高人详细解释,感激不尽。

  • 写回答

1条回答 默认 最新

  • solomon5926 2014-10-05 00:27
    关注

    我估计你用个MySQL版本是5.5,我用的是5.1,处理的方式是小数点后5位开始使用科学计算法,5.5的处理方式是小数点后16位开始使用科学计算法。如果你在字段类型声明中没有指定M和D的值,MySQL就会这样去处理double类型的小数点,如果你指定了M和D值,MySQL就会按照你指定的精度显示。关于M和D的说明如下:
    mysql> ? double
    Name: 'DOUBLE'
    Description:
    DOUBLE[(M,D)] [UNSIGNED] [ZEROFILL]

    A normal-size (double-precision) floating-point number. Permissible
    values are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0, and
    2.2250738585072014E-308 to 1.7976931348623157E+308. These are the
    theoretical limits, based on the IEEE standard. The actual range might
    be slightly smaller depending on your hardware or operating system.

    M is the total number of digits and D is the number of digits following
    the decimal point. If M and D are omitted, values are stored to the
    limits permitted by the hardware. A double-precision floating-point
    number is accurate to approximately 15 decimal places.

    UNSIGNED, if specified, disallows negative values.

    URL: http://dev.mysql.com/doc/refman/5.1/en/numeric-type-overview.html

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图