Why is this, how is this

Why 5 % 20 result 5

Why this happens?

Because 5 รท 20 = 0 with a remainder of 5.

Yes, we could also say that it is 1/4 or 0.25, but the concept of remainder or modulus come from the idea of whole number division.

Another way to think of this is:

modulus = dividend - Math.floor(dividend / divisor)

// or

modulus = dividend - Math.floor(quotient)

In this case, Math.floor(quotient) is 0.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.