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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting percentages straight

Status
Not open for further replies.

flaviooooo

Programmer
Feb 24, 2003
496
0
0
FR
Hey,

I'm having some problems with the following:

we have a designcode that consists of several inks. Every ink is defined as to having a certain amount of KG in the design, and then a column percentage is set that shows how much of the design this ink is part of... sounds complicated, but isnt.

For example Design X consists of 20 KG of ink A, and 30 kg of ink B -> ink A is used 40%, ink B 60%

So far so good, but now I see that the percentages aren't always 100%, but 100,01 or so...

An example:

FORMULA_ID CODE KG Percentage
00MR00004 R511-321433A 1,5 7,49 (0,0749)
00MR00004 R513-843775A 0,44 2,20 (0,022)
00MR00004 R517-909587A 0,3 1,50 (0,015)
00MR00004 R519-029382A 17,8 88,82 (0,8882)

Total Percentage = 100,01%

Is there any way I can fix this, so that it always equals 100% in total?

Thanks in advance
 
I would first confirm the calculations are correct. I expect you are seeing rounding in your numbers. What do
The actual percentages from your numbers are:
[tt][blue]0.074850299
0.021956088
0.01497006
0.888223553[/blue][/tt]



Duane MS Access MVP
 
As dhookum says, the problem is rounding. The results you show are actually correct, but rounding makes them look wrong.

The problem is inevitable. Take a case where you have three inks in proportion 1:1:1. The real proportions are 33.333333333333... percent but rounding to two decimal places you get 33.33% and a total of 99.99%. However many decimal places you include you will always get under 100%. Further, there are no grounds on which you can make one ink 33.34% to make the total correct, all three inks are equivalent.

This happened to me last week on an invoicing issue. I had to give someone a 0.01% discount.

Ian
 

If you round your calculations to 5 decimals (while formatting them to 4) and round your summing to 4 decimals, you might have less cases of 0.01% error
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top