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 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型