From: Alex Keda Date: February 15 2013 11:07am Subject: Re: MySQL 5.1: incorrect arithmetic calculation List-Archive: http://lists.mysql.com/mysql/228979 Message-Id: <511E16F7.4050602@lissyara.su> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 15.02.2013 14:43, Johan De Meersman пишет: > > ----- Original Message ----- >> From: "Alex Keda" >> >> mysql> SELECT SUM(`Amount`*`Cost`*(1-`Discont`)) as `Summ` FROM `WorksCompliteAgregate` WHERE (`ContractID` = 10369 AND `Month` = 497); > Based off the select you printed, this comes to EXACTLY 548.595 for the first row and 0 for the second row. > > >> mysql> SELECT SUM(`Amount`*`Cost`*(1-`Discont`)*100)/100 as `Summ` FROM `WorksCompliteAgregate` WHERE (`ContractID` = 10369 AND `Month` = 497); > The more detailed result here, though, seems to suggest that there's a longer fraction in your table than is printed by your select. Would your column happen to be a Float? > >> but, my desktop calculator gives the result 548.60 > Which is the correct rounding for 548.595. Check if your column is a float, and if it is, go google for floating point mathematics. They do not work the way you think they do. Use decimal(n,m) for money - or any discrete number, for that matter. Floats are not exact values, they are APPROXIMATE values. > > https://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html may also give you an idea of what goes wrong. > > OK. But, how about: mysql> SELECT 365 * 1.67 * ( 1 - 0.10); +--------------------------+ | 365 * 1.67 * ( 1 - 0.10) | +--------------------------+ | 548.5950 | +--------------------------+ 1 row in set (0.00 sec) mysql> ??