2015-04-17 49 views
0

mysql數字列表的簡單精度問題與單個計算的總和計算方法不同。 (如何處理這個塞納里奧?)有一(1)美分的差異?行帶有十進制字段的函數SUM的Mysql(5.5)精度問題

樣品:

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

回答

0

閱讀本文article。浮點數不作爲精確值存儲,因此可能存在計算精度問題