SA-MP Forums Archive
number % 2 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: number % 2 (/showthread.php?tid=355840)



number % 2 - Supercop - 01.07.2012

What is "%" used for when calculating something in the script?

Like:

6 + 2 = 8

6 / 2 = 3

But what can "6 % 2" do?


Re: number % 2 - Vince - 01.07.2012

This is the modulus and calculates the remainder of a division. It is frequently used to check if a number is odd or even.

6 / 2 returns a whole number (3), and thus the remainder is 0. (3 * 2 = 6).
6 / 4 returns 1 and the remainder is 2. (1 * 4 + 2 = 6).


Re: number % 2 - Hiddos - 01.07.2012

% gives you the remainder of x / y.

For example:

8 % 2 = 0

7 % 3 = 1

12 % 5 = 2

15 % 28 = 15