List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:May 29 2006 6:13am
Subject:Re: select sum(qty*unitpri) wrong result
View as plain text  
In the last episode (May 29), wang shuming said:
> Hi,
>  table a1
> 
> qty int(10) , unitpri float(10,2)
> 350            19.80
>   ...
> 350     19.80    (total 48 lines)
> 
> select sum(qty*unitpri)  from a1
> 332639.99  ,it should return  332640.00
> 
> mysql version 4.1.19

If you want exact arithmetic, don't use FLOATs. Use the DECIMAL type
instead:

http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html

-- 
	Dan Nelson
	dnelson@stripped
Thread
select sum(qty*unitpri) wrong resultwang shuming29 May
  • Re: select sum(qty*unitpri) wrong resultDan Nelson29 May
  • Keyword - MySQL 4.1ManojW29 May
    • Re: Keyword - MySQL 4.1Keith Roberts29 May