Mysql(5.5)精度问题,带有十进制字段的函数SUM

时间:2015-04-17 11:10:46

标签: mysql

mysql数字列表的简单精度问题不能计算与单个计算相同的和。 (如何处理这个事件?)有一(1)分的差异?

行样本:

Select qty, (qty*21.25)
6.5  | 138.125
0.5  | 10.625
0.5  | 10.625
0.25 | 5.3125
1    | 21.25
2    | 42.5
1    | 21.25
2    | 42.5
2.5  | 53.125
2.5  | 53.125
2    | 42.5
3    | 63.75
3    | 63.75
3.5  | 74.375

样本2:

Select sum(qty), sum(amount)
30.25 | 642.8175

样本3:

Select 30.25*21.25
642.8125

Since the answer was so vague. Let try this. Can anyone explain why the mysql statement produces the wrong results. SELECT 6.875+3.125 10.00 Shouldn't this be 10.01

1 个答案:

答案 0 :(得分:0)

阅读此article。浮点数不会存储为精确值,因此可能存在计算精度问题