Hello!
I am currently reading trough the basics of scripting in the roblox devhub.
When I read the Operators Operators | Roblox Creator Documentation one Arithmetic confused me a bit. It was the % (Modulus) operator.
I have tried to learn it on my calculator and on the internet. But didn’t find anything good.
Could anyone explain to me what % is and how to use it?
1 Like
It’s basically a way to get the remainder of a division
print(3%2) -- prints 1
print(5%5) -- prints 0
print(5%10) -- prints 5
It can also be used to get the decimal part of a number via doing %1
print(3.646%1) -- prints 0.646
5 Likes
so it works like that as well huh, thx
1 Like
A good tip, its useful for knowing if a number is even or odd
Just say
if number % 2 == 0 then
Or
if number % 2 == 1 then
if % returns zero, its even, if it returns one, its odd
3 Likes