This week's book giveaway is in the Performance forum.We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!

percentage of time

jay williams
Greenhorn
Posts: 1
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%

Pauline McNamara
Sheriff
Posts: 4012
6
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: 12145
30
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
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: 1068
4
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: 12145
30
Ryan,

isn't doing 660 * 0.3 using floating point arithmetic?
[ June 16, 2005: Message edited by: fred rosenberger ]

Ryan McGuire
Ranch Hand
Posts: 1068
4
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