I just want to point out the simple answer, just in case you're not aware of it.
Using the code in your second post, if you want the division expression to result in a floating point number, just convert one or both of the integral operands before the division operation --
(float)capacity/level -- and the result will be a floating point number.
Now, it won't be 1.333... with the 3's repeating forever, because Java is running on a computer and there is a need to represent data (and numbers) in a finite amount of space, and so begins the not-so-simple answer. The bit
pattern used for floating point numbers (IEEE 754) doesn't provide for never-ending values to be represented. Instead, it makes an approximation that can be stored in the amount of space allocated (which in the case of floats is 4 bytes).
Even if you were to work with BigDecimal, which can represent floating point numbers to an arbitrary degree of precision, the never-ending 3's would still need to be truncated at some point. If float or double don't offer enough decimal points for you, then use BigDecimal and specify your own number of decimal points.
Is your solution becoming clearer?
[ December 08, 2003: Message edited by: Dirk Schreckmann ]