aspose file tools*
The moose likes Programming Diversions and the fly likes percentage of time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "percentage of time" Watch "percentage of time" New topic
Author

percentage of time

jay williams
Greenhorn

Joined: Jun 12, 2005
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%

please help
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
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

Joined: Oct 02, 2003
Posts: 11229
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
If you want it pretty exact, don't do the arithmetic using integers. Do it using a real number representation.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ryan McGuire
Ranch Hand

Joined: Feb 18, 2005
Posts: 1006
    
    3
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

Joined: Oct 02, 2003
Posts: 11229
    
  16

Ryan,

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

Joined: Feb 18, 2005
Posts: 1006
    
    3
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: percentage of time