# percentage of time

jay williams

Greenhorn

Posts: 1

Pauline McNamara

Sheriff

Posts: 4012

6

Barry Gaunt

Ranch Hand

Posts: 7729

posted 11 years ago

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

Posts: 1085

4

Ryan McGuire

Ranch Hand

Posts: 1085

4

posted 11 years ago

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

Originally posted by fred rosenberger:

Ryan,

isn't doing 660 *0.3using 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