This content has been marked as final. Show 4 replies
It's what I want in the end but I'm completely confused on how the program is getting it when it shouldn't ( I think?)
Yes it should.
393.7 divided by 12 = 32.80833
An even number of feet is 32 so 32 * 12 = 384 inches.
You started with 393.7 inches so 393.7 - 384 = 9.7 inches remaining.
Ah I see now. I was under the misunderstanding that Java converted to decmial form when instead it stays elementry and just leaves everything as a remainder and doesn't convert it.
Alright that makes a lot of sense now. Thank you.
EDIT: I think the reason I was getting tripped up was because when I was just having inches/12 it was giving me the answer with a decimal form and I was expecting the modulus to do the same but only the decimal part.
Edited by: 960813 on Sep 23, 2012 6:28 PM
For the detailed spec see 15.17.3. Remainder Operator % (the entire section 15.17 really) of The Java Language Specification
The binary % operator is said to yield the remainder of its operands from an implied division; the left-hand operand is the dividend and the right-hand operand is the divisor.
In C and C++, the remainder operator accepts only integral operands, but in the Java programming language, it also accepts floating-point operands.
The remainder operation for operands that are integers after binary numeric promotion (§5.6.2) produces a result value such that (a/b)*b+(a%b) is equal to a.
This identity holds even in the special case that the dividend is the negative integer of largest possible magnitude for its type and the divisor is -1 (the remainder is 0).
It follows from this rule that the result of the remainder operation can be negative only if the dividend is negative, and can be positive only if the dividend is positive. Moreover, the magnitude of the result is always less than the magnitude of the divisor.
If the value of the divisor for an integer remainder operator is 0, then an ArithmeticException is thrown.
Cross posted (and didn't bother to inform the other forum about the responses and help received here)