Go back to previous page
Forum URL: http://www.cut-the-knot.org/cgi-bin/dcforum/forumctk.cgi
Forum Name: College math
Topic ID: 11
#0, rounding data
Posted by Chris Morris on Nov-01-00 at 02:09 PM
Dear Alexander,


Problem: To make all integer percentages add up to 100%

To calculate the percentages, I divide each number by the total of all the numbers (and multiply by 100). A this point of course they all add up to 100, however I need integer percentages, so my problem really occurs in the conversion from floating point numbers to integers.

Here is an example of my problem

If the percentages work out to be

10.2
30.65
28.55
30.6


These floting point numbers all add up to 100. The integer parts add up to 98. If I round the values ie( 10,31,29,31) they add up to 101.

One way I thought about doing it was to add up all the fraction parts in this case (0.2+0.65+0.55+0.6) = 2. Therefore the rounding process should generate an additional 2%, I could then order the fractional parts (0.2, 0.55, 0.6, 0.65) Starting at the right hand side I could round up 2 values and round the rest down.

ie
Round the last 2 numbers up

.65 rounds to 1 (add 1 to the integer part = 31)
.6 rounds to 1 (add 1 to the integer part = 31)

and now round the rest down

.55 rounds to 0 (add 0 to the integer part = 28)
.2 rounds to 0 (add 0 to the integer part = 10)

The percents then all add up to 100, (31+31+28+10) = 100

I was hoping there was a simpler approach...

TIA
Chris Morris

-----Original Message-----
From: Alexander Bogomolny
Sent: 22 January 2000 13:08
To: chris@morris.net
Subject: Re: Form posted from Microsoft Internet Explorer.


How do you convert the numbers to percentages?


#1, RE: rounding data
Posted by alexb on Nov-01-00 at 02:12 PM
In response to message #0
Chris, I can assure you that there is no simple solution to the problem. It is not mathematical at all and the solution must fit into the nature of your application. If the approach you presented works for you, just go ahead and use it without looking for a simpler one. There is none. There is no universal approach to squeezing information expressed by real numbers into an integer presentation.

All the best,
Alexander Bogomolny