# Thread: A sum problem (2 decimal only)

1. Registered User
Join Date
Jul 2003
Location
Portugal
Posts
111

## Unanswered: A sum problem (2 decimal only)

Some calculated fields give something like this:

22507,397260274 -> shows 22507,40 (formated 2 decimal)
374,794520547945 -> shows 374,79
149,753424657534 -> shows 149,75
------------------------------ Sum: 23.031,95 when it couldt give 23.031,94

Is there an idea to make it works?

Thanks,

Ruas

2. Registered User
Join Date
Feb 2004
Posts
142
Floating point calcs can be a bit of a pain. If I need to get results that actually use the rounded numbers before calculation I create a function that I embed into the query

Public Function RoundIt_2(dblVarIn as double) as double
On error resume next
Roundit_2 = (dblVarIn*100)/100
if err.number <> 0 then
RoundIt_2 = dblVarIn
end if
End Function

Usually works, if you expect that nulls might get into the function then trap them asnd return zero.

3. Registered User
Join Date
Mar 2002
Posts
32

## Re: A sum problem (2 decimal only)

Originally posted by jmruas
Some calculated fields give something like this:

22507,397260274 -> shows 22507,40 (formated 2 decimal)
374,794520547945 -> shows 374,79
149,753424657534 -> shows 149,75
------------------------------ Sum: 23.031,95 when it couldt give 23.031,94

Is there an idea to make it works?

Thanks,

Ruas

This rounds off to 23,031.95

Looks like it sums fine.

4. Registered User
Join Date
Jul 2003
Location
Portugal
Posts
111
Yes, Ben, it sums fine

But, as the result is shown with 2 decimal and the sum isn't, then we have a good sum (23,031.95), with a bad result(23,031.94)!

Now I'll try the function sent by AZ KC (thank you!)...

Thank you

Ruas
Last edited by jmruas; 03-03-04 at 14:24.

5. Registered User
Join Date
Feb 2004
Posts
142
i forgot to include the most important piece this morning

Cint(somedouble*100)/100 this will round to two places.