0

Please can someone explain this % to me? I don't understand how its calculated.

Calculation

19th Jul 2017, 8:32 PM
Daniel
Daniel - avatar
3 Respostas
+ 1
if you have 2 integers - say x and y - x % y is the remainder when you divide x by y. So 19 % 3 = 1, because when you divide 19 by 3 you get 6 remainder 1. 24 % 4 = 0, because 24 divided by 4 is 6 with 0 remaining. The companion operator is integer division, written '//'. So 19 // 3 = 6 (we disregard the remainder.
19th Jul 2017, 8:43 PM
Rob Sykes
Rob Sykes - avatar
+ 4
Basically, it returns a remainder of the division. Somewhat easily understood for positive numbers, as 12 % 5 = 2 (12/5 = 2 and 2 as a remainder), it gets tricky when negatives are concerned: 12 % 5 = 2 (2*5 +2) 12 % -5 = -3 (3*-5 -3) -12 % 5 = 3 (-3*5 +3) -12 % -5 = -2 (-2*-5 -2)
19th Jul 2017, 8:43 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
19th Jul 2017, 8:32 PM
Mario L.
Mario L. - avatar