dkmarsh99 Posted January 18, 2015 Share Posted January 18, 2015 HI. I have written a mysql database query to add up invoice totals. It seems to be automatilaly adding .01 to the result when I run a group by. Let me explain more .. When I do a select on the field that I am adding up the result is $132.25 - the query is as follows select ttl_invoice_due from 65_it where st_id = 96011; When I run the following query that uses sum and group by - the $132.25 becomes $132.26 - the sum query is SELECT 65_st.job_compid, 65_client.uid_client, 65_client.comp_name, Sum(65_it.ttl_invoice_due) AS SumOftotal_due, Sum(65_it.ttl_invoice) AS SumOftotal_invoice, Sum(65_it.ttl_invoice_payments) AS SumOftotal_amnt_paid FROM 65_client INNER JOIN (65_st INNER JOIN 65_it ON 65_st.st_id = 65_it.st_id) ON 65_client.uid_client = 65_st.uid_client WHERE 65_st.uid_client = 1905 and 65_st.job_compid = 1 and 65_st.sales_date<=curdate() GROUP BY 65_st.job_compid, 65_client.uid_client HAVING (((Sum(65_it.ttl_invoice_due))<>0)) order by 65_client.comp_name; The 65_it.ttl_invoice_due field is defined in the table as Double(12,2) I dont know why the sum is returing $132.26 where it should be $132.25 as in the simple query ?. Quote Link to comment https://forums.phpfreaks.com/topic/294033-mysql-query-rounding-incorrectly-adding-1-cent/ Share on other sites More sharing options...
Barand Posted January 18, 2015 Share Posted January 18, 2015 Use DECIMAL type for currency The DECIMAL and NUMERIC types store exact numeric data values. These types are used when it is important to preserve exact precision, for example with monetary data. Quote Link to comment https://forums.phpfreaks.com/topic/294033-mysql-query-rounding-incorrectly-adding-1-cent/#findComment-1503336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.