I’m trying to see how often a certain number is divisible by (in this case) 20, how would i go at it?
Do you mean like a number is inserted and then divided by 20 without being a decimal number?
I’m having a hard time understanding what you’re trying to say.
You could use Modulus a.k.a. %.
not what im trying, lets say i have 182, as a human i of course knew that its divisible by 20 9 times with 2 as a rest, but how would i go at it in script, i am currently just doing it like this:
for i = 1, TempVal do
if TempVal - 20 > 0 then
TempVal = TempVal - 20
end
end
Yes as I stated, modulus could be used for it.
Use modulo!
The symbol is %
(procent sign) and by using modulo on two numbers it will return the rest from the division (using integers).
20 % 5 --0
22 % 5 --2
5 % 2 --1
10 % 2 --5
If a modulo division returns 0, you know the numbers are divisible.
i don’t want to know the rest mate, i want to know how often it is divisible
Then just divide the number and delete the decimal part. There are a few ways to achieve this, maybe with math.floor
.
For example,
local value = 182
print(math.floor(value/20))
thank you, i completely forgot about math.floor(i dont have many occasions where i need to use it)