This content has been marked as final.
Show 4 replies

1. Re: Question about how Modulus works
rp0428 Sep 23, 2012 8:05 PM (in response to calistoknight)>
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. 
2. Re: Question about how Modulus works
calistoknight Sep 23, 2012 8:29 PM (in response to rp0428)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 
3. Re: Question about how Modulus works
rp0428 Sep 23, 2012 8:37 PM (in response to calistoknight)For the detailed spec see 15.17.3. Remainder Operator % (the entire section 15.17 really) of The Java Language Specification
http://docs.oracle.com/javase/specs/jls/se7/html/jls15.html
>
The binary % operator is said to yield the remainder of its operands from an implied division; the lefthand operand is the dividend and the righthand operand is the divisor.
In C and C++, the remainder operator accepts only integral operands, but in the Java programming language, it also accepts floatingpoint 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. 
4. Re: Question about how Modulus works
darrylburke Sep 24, 2012 5:08 AM (in response to calistoknight)Cross posted (and didn't bother to inform the other forum about the responses and help received here)
http://www.javaforums.org/newjava/63229questionabouthowmodulusworks.html
db