Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Group and Sum with two decimal places

Status
Not open for further replies.

Welshbird

IS-IT--Management
Joined
Jul 14, 2000
Messages
7,378
Location
DE
I have a table with two codes and a value as a number with two decimal places.

When I group by the codes and sum the figures I always get results which have more decimal places.

Am I being daft? (Be kind when you answer that!) Surely a lot of numbers with two decimal places can only ever add up to an answer with two decimal places?

Any ideas guys?

Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
Floating point numbers (Single or Double) are only approximations.
You may try this:
SELECT code, Round(Sum(figure),2) AS Total
FROM theTable
GROUP BY code

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yeah - I have done that, but it can still give me a penny out.

What I don't understand is that I am importing a figure from a flat file with two decimal places. So originally it really did have two decimal places.

Would I get an accurate answer if I import as integers and do all the calculations as integers (and just divide by 100 at the end)

Fee

The question should be [red]Is it worth trying to do?[/red] not [blue] Can it be done?[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top