CTK Exchange
Front Page
Movie shortcuts
Personal info
Awards
Reciprocal links
Privacy Policy

Interactive Activities

Cut The Knot!
MSET99 Talk
Games & Puzzles
Arithmetic/Algebra
Geometry
Probability
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
My Logo
Math Poll
Other Math sit's
Guest book
News sit's

Manifesto: what CTK is about |Store| Search CTK Buying a book is a commitment to learning Table of content Things you can find on CTK Chronology of updates Email to Cut The Knot

CTK Exchange

Subject: "Dear Alexander, Problem: To make al..."     Previous Topic | Next Topic
Printer-friendly copy     Email this topic to a friend    
Conferences The CTK Exchange College math Topic #26
Reading Topic #26

Charter Member
Dec--, 00: AM (EST)
Click to EMail Click to send private message to Click to add this user to your buddy list  
"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 [pre] .65 rounds to 1 (add 1 to the integer part = 31) .6 rounds to 1 (add 1 to the integer part = 31) [/pre] and now round the rest down [pre] .55 rounds to 0 (add 0 to the integer part = 28) .2 rounds to 0 (add 0 to the integer part = 10) [/pre] The percents then all add up to 100, (31+31+28+10) = 100 I was hoping there was a simpler approach... TIA Chris Morris "
 
  

Attachments
https://www.cut-the-knot.org/htdocs/dcforum/User_files/ChrisMorrisGuest

  Alert | IP Printer-friendly page | Edit | Reply | Reply With Quote | Top

Conferences | Forums | Topics | Previous Topic | Next Topic

You may be curious to visit the old CTK Exchange archive.

|Front page| |Contents|

Copyright © 1996-2018 Alexander Bogomolny

[an error occurred while processing this directive]
 Advertise

New Books
Second editions of J. Conway's classic On Numbers And Games and the inimitable Winning Ways for Your Mathematical Plays