The modulo operator is the remainder operator. it says what is left after I divide x by y. So if you do 10 % 2 you get zero because 10 / 2 = 5 with nothing remaining. If you do 10 % 4 you get 2 because 10 / 4 = 2 so 4 goes into 10 two times and there will be 2 remaining. The way to calculate % is
let x = number to get the mod from
let y = number to mod against
mod = x - ((x / y) * y)
2 = 10 - ((10 / 4) * 4)
2 = 10 - (2 * 4)
2 = 10 - 8
2 = 2
this calculation only works when doing integer division
NathanOliver
Veteran Poster
1,084 posts since Apr 2009
Reputation Points: 215
Solved Threads: 189