A rounding problem on calculated controls

T

Tony Williams

I have 7 calculated controls on a report. The formula for each control is
(Nbr of reported clients in category/total nbr of reported clients) X total
of actual clients. The values for total reported clients is 39529 and the
total of actual clients is 44183. This is how the actual numbers look to 2
decimal places

cat1.......12920................Adjusted value(cat1/39529)X44183=14441.15
cat2........8060................Adjusted value(cat2/39529)X44183=9008.95
cat3........11335..............Adjusted value(cat3/39529)X44183=12669.54
cat4........2214................Adjusted value(cat4/39529)X44183=2474.66
cat5........124..................Adjusted value(cat5/39529)X44183=138.59
cat6........437..................Adjusted value(cat6/39529)X44183=488.45
cat7........4439................Adjusted value(cat7/39529)X44183=4961.63

Obviously I can't have part of a client so I have set the format to 0
decimal places and the report shows these figures:
cat1.......14441
cat2.......9009
cat3.......12670
cat4.......2475
cat5.......139
cat6........488
cat7......4962

Which you can see now add up to 44184. How can I cahnge my formula or format
of the calculated controls so that the report shows my correct totals?
Any help would be appreciated. I've been working on this for days using the
Round function, the Int function but can't get the desired result.
Many thanks
Tony
 
S

Svetlana

Why dont you break the result of yout total into another control so you
can use the format you wish?
 
W

Wayne Morgan

Displaying 0 decimals is just that, you're displaying it that way. It
doesn't change the value that's actually there. Instead, you need to round
off your equations to 0 decimal places. If you just want to drop the
fraction, you could wrap the equation in an Int() or Fix() function. If you
want to round off the result, you have a couple of options. There is a
Round() function that you could use, but it uses "banker's" or "scientific"
rounding. This will round .5 to the nearest even number. While this has some
technical advantages, most folks like to round .5 up all of the time. If so,
you'll have to do the rounding yourself.

Examples:
Truncate
Int((cat1/39529)*44183)
or
Built-in Round()
Round((cat1/39529)*44183, 0)
or
Round .5 Up
Int(((cat1/39529)*44183) + 0.5)

The difference between Fix() and Int() is with the way negative numbers are
handled. There is no difference if you're always using positive numbers.
Fix() will simply truncate (delete) the decimal portion. Int() gives you the
nearest integer less than the number.

Example:
Fix(-3.4) = -3
Int(-3.4) = -4

-4 is the first integer less than -3.4.
 
T

Tony Williams

Thanks Wayne. I have tried using Int and Round but cannot get the answer to
come out at the figure I want which is 44183. As you can see some of the
numbers are more that .5, others are less. I haven't tried rounding down
because I'm not sure how to do that. I tried using Int and that didn't give
me the right answer, it gave me 44179 (14441+9008+12669+2474+138+488+4961).

I think what I want is for the report to calculate the controls, check them
against the total I want and if the totals don't agree adjust one or more of
the individual calculated controls so that it gives me a list of whole
numbers that do add up. I can see the logic in that but don't know how to
apply it.
Any ideas?
Thanks again
Tony
 
W

Wayne Morgan

If you add them before rounding it comes to 44182.97. If you then round
that, you'll get your 44183. Whenever you deal with rounding, some error is
likely to creep in. In this case, I would round after you make the total,
not before. You can display the values as 0 decimals if you want, but add
with the actual values then round.
 
T

Tony Williams

Thanks for that advice Wayne I'll have a look at trying that way.
Cheers
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top