Link to home
Start Free TrialLog in
Avatar of gpdixit
gpdixit

asked on

MS Access 2003 - sum is producing too many decimal places

SELECT tblDrafts.D_CaseNumber, Sum(tblDrafts.D_Amount) AS SumOfD_Amount
FROM tblDrafts
GROUP BY tblDrafts.D_CaseNumber;

produces sum with many decimal digits instead of two digits as defined in the table. By using Round function, it is not giving correct sum in decimal values. Example, the value in table is say 169531.10 and it is showing 169531.09 because it is rounding 169531.09354...
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try this

SELECT tblDrafts.D_CaseNumber, formatnumber(Sum(tblDrafts.D_Amount),2) AS SumOfD_Amount
FROM tblDrafts
GROUP BY tblDrafts.D_CaseNumber;
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Always - always - use data type Currency for currency, amounts, etc.

If you can 't change the fields of the table, convert to Currency at the earliest stage:
SELECT 
  tblDrafts.D_CaseNumber, 
  Sum(CCur(tblDrafts.D_Amount)) AS SumOfD_Amount
FROM 
  tblDrafts
GROUP BY 
  tblDrafts.D_CaseNumber;

Open in new window


The reason for your rounding errors is caused by adding positive and negative amounts when these are Single or Double.

/gustav
I was wondering when your "Spidey sense" would start tingling, gustav :)
Believe me, it's operating at random!

/gustav
Avatar of gpdixit
gpdixit

ASKER

Expert gave two solutions, out of which second solution was acceptable. I tried and and it is successful. Solution was provided in a very short time. Lot of thanks.