CREATE TABLE `helei` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `num1` double DEFAULT NULL,
  `num2` double DEFAULT NULL,
  `num3` decimal(5,3) DEFAULT NULL,
  `num4` decimal(5,3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1;


mysql> select * from helei;
+----+------+------+-------+-------+
| id | num1 | num2 | num3  | num4  |
+----+------+------+-------+-------+
|  1 |    1 |    1 | 1.000 | 1.000 |
|  2 |    2 |    2 | 2.000 | 2.000 |
|  3 |    3 |    4 | 3.000 | 4.000 |
|  4 |    6 |    5 | 6.000 | 5.000 |
|  5 |  3.3 |  4.4 | 3.300 | 4.400 |
|  6 |  6.6 |  5.5 | 6.600 | 5.500 |
+----+------+------+-------+-------+
6 rows in set (0.00 sec)


mysql> select (num2-num1)num5,(num4-num3)num6 from helei;
+---------------------+--------+
| num5                | num6   |
+---------------------+--------+
|                   0 |  0.000 |
|                   0 |  0.000 |
|                   1 |  1.000 |
|                  -1 | -1.000 |
|  1.1000000000000005 |  1.100 |
| -1.0999999999999996 | -1.100 |
+---------------------+--------+
6 rows in set (0.00 sec)


可以看到double列的减法出现了问题,我们可用demical替换即可

本文出自 “岁伏” 博客,请务必保留此出处http://suifu.blog.51cto.com/9167728/1783861

posted on 2016-08-19 17:14  岁伏  阅读(555)  评论(0编辑  收藏  举报