This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

percentage of time

 
jay williams
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i need to work out 30% of 11min
then plus that to the 11 to get a new time

then minus the 30% from 11 for another time

i cant work out how to put my caculations back into correct time

I need 11 min +30%
and 11 min -30%

please help
 
Pauline McNamara
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jay, welcome to Javaranch!

Since your question doesn't have much to do with Orion, I'm moving your post to Programming Diversions.

Good luck!

Pauline
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so you want 11 minutes plus (30% of 11 minutes)?

that's just 130% of 11 minutes.

if you want 11 minutes minus 30%, you just want 70% of 11.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want it pretty exact, don't do the arithmetic using integers. Do it using a real number representation.
 
Ryan McGuire
Ranch Hand
Posts: 1061
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
11 min = 660 sec

30 % of 11 min = 660 * .3 = 198 sec = 3 min, 18 sec

11 min + 30% = 14 min 18 sec
11 min - 30% = 7 min 42 sec

No need for floating point.
[ June 16, 2005: Message edited by: Ryan McGuire ]
 
fred rosenberger
lowercase baba
Bartender
Posts: 12122
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan,

isn't doing 660 * 0.3 using floating point arithmetic?
[ June 16, 2005: Message edited by: fred rosenberger ]
 
Ryan McGuire
Ranch Hand
Posts: 1061
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:
Ryan,

isn't doing 660 * 0.3 using floating point arithmetic?

[ June 16, 2005: Message edited by: fred rosenberger ]


In general, yes.

However since the values are "hardcoded" (we're only doing +/- 30% of 11 min, not x% of y min), we can use our own brains to do the floating point arithmetic, and then use Java (or whatever) to print out what turn out to be integers (or even Strings).



If we MUST show some calculations, we can still use the fact that the denominator of the simplest form fraction for 30% divides evenly into the base time (30%=3/10 and 10 gazinta 11*60 evenly) to allow us to use integer math:



Ryan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic