[try Beta version]
Not logged in

 
 
Modulus question

Feb 26, 2011 at 11:38pm
Quick question, I am trying to find the remainder
of 4/10, apparently I'm getting 4, shouldn't it be 0?
Am I doing something wrong here?
Last edited on Feb 26, 2011 at 11:41pm
Feb 26, 2011 at 11:45pm
is this a serious question? 4/10 is 0 with a remainder of 4
Feb 26, 2011 at 11:48pm
I am putting in 4%10 and 4 is being spit out.
Shouldn't it be 0?
Feb 26, 2011 at 11:50pm
As in 4/10 = .4
and 4%10 = 0
Feb 26, 2011 at 11:51pm
do you understand what modulus does? It gives you the remainder after division. 4/10 is 0 and 4%10 is 4, as 10 goes into 4 zero times leaving 4 as a remainder.
Feb 26, 2011 at 11:52pm
with integers 4/10 is not 0.4, you can only have whole number results, so 4/10 is 0
Feb 26, 2011 at 11:56pm
Hmmm... oh okay, I think I understand it now.

Let me see if I have this clear then:
The answer is 0.4 right?
So, 4/10 will give me the first part: 0
and, 4%10 will give me everything after the decimal: 4

I was thinking it gave the long-division remainder.
But if that's how it works, then, thanks for the help/clarification!
Feb 27, 2011 at 12:07am
no it doesn't give you the bit after the decimal point, as it doesn't give you any value related to the result of long division like you're thinking.

if you do long division on 5/2 for example you get 2.5, but with integer division 5/2 is 2 and 5%2 is 1, as 5/2 leaves a remainder of 1, the modulus gives you the remainder after integer division, not the number after the decimal point, there is no decimal point with integers, only whole numbers
Feb 27, 2011 at 12:14am
Oooohhh, okay, okay, I see how it works now!
Thanks for the help!
Topic archived. No new replies allowed.