Modulus question

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
is this a serious question? 4/10 is 0 with a remainder of 4
I am putting in 4%10 and 4 is being spit out.
Shouldn't it be 0?
As in 4/10 = .4
and 4%10 = 0
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.
with integers 4/10 is not 0.4, you can only have whole number results, so 4/10 is 0
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!
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
Oooohhh, okay, okay, I see how it works now!
Thanks for the help!
Topic archived. No new replies allowed.