From: Alex Keda Date: February 15 2013 5:35am Subject: MySQL 5.1: incorrect arithmetic calculation List-Archive: http://lists.mysql.com/mysql/228976 Message-Id: <511DC92D.8070708@lissyara.su> MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1251; format=flowed Content-Transfer-Encoding: 8bit bkp0# mysql h5000_bill Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1643184 Server version: 5.1.68-log FreeBSD port: mysql-server-5.1.68 Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> set names utf8; Query OK, 0 rows affected (0.00 sec) mysql> SELECT * FROM `WorksCompliteAgregate` WHERE (`ContractID` = 10369 AND `Month` = 497); +----------+------------+-------+-----------+----------+--------+---------+--------+ | ID | ContractID | Month | ServiceID | Comment | Cost | Discont | Amount | +----------+------------+-------+-----------+----------+--------+---------+--------+ | 10551851 | 10369 | 497 | 10000 | ¹20440 | 1.67 | 0.10 | 365 | | 10551854 | 10369 | 497 | 20000 | ¹20441 | 150.00 | 1.00 | 1 | +----------+------------+-------+-----------+----------+--------+---------+--------+ 2 rows in set (0.00 sec) mysql> SELECT SUM(`Amount`*`Cost`*(1-`Discont`)) as `Summ` FROM `WorksCompliteAgregate` WHERE (`ContractID` = 10369 AND `Month` = 497); +--------+ | Summ | +--------+ | 548.59 | +--------+ 1 row in set (0.00 sec) mysql> SELECT SUM(`Amount`*`Cost`*(1-`Discont`)*100)/100 as `Summ` FROM `WorksCompliteAgregate` WHERE (`ContractID` = 10369 AND `Month` = 497); +------------+ | Summ | +------------+ | 548.594985 | +------------+ 1 row in set (0.00 sec) mysql> SELECT 365 * 1.67 * ( 1 - 0.10); +--------------------------+ | 365 * 1.67 * ( 1 - 0.10) | +--------------------------+ | 548.5950 | +--------------------------+ 1 row in set (0.00 sec) mysql> =============== but, my desktop calculator gives the result 548.60