|
I recently started seeing % around.
I looked online for the formula for it and I'm a little confused about it. But I was wondering what uses it could have? Can someone explain the formula for me? Thanks. |
|
|
Title Fix:
Use of % / Modulus? |
|
|
Well it returns the remainder of division. For example 10 % 3
Well 3 goes into 10, 3 times;
3 + 3 + 3 = 9
If you add it again it'll be over 10, since there was 1 left over, the remainder is one, so
10 % 3 = 1 |
|
|
I think I understand.
so;
15 % 4 = 3
4 + 4 + 4 = 12
15 - 12 = 3
Is that right?
If so, where can I apply this to scripting? |
|
|
Yes, exactly. You could check if a number is even;
N = 5
if N % 2 == 0 then
print("Number is even!")
else
print("Number is odd!")
end
Or you could use it for some sort of algorithm or even to check if a value had increase by +5 (I've seen leaderboards use it to award points) |
|
|
Ahhh. I see. Thank you for the clarification!
Checking whether a number is odd or even can be very useful in some cases, I'd imagine.
Thanks. :) |
|
|
For a few more practical uses;
http://stackoverflow.com/questions/2609315/recognizing-when-to-use-the-modulus-operator |
|
|
Then, not much more information, but this has more example;
http://stackoverflow.com/questions/3589976/what-are-the-practical-uses-of-modulus-in-programming |
|
|
The examples are in C# but there's here;
http://watchhogstories.wordpress.com/2008/08/11/coding-practices-the-modulus-operator/ |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
You'll need it in many algorithms.
Basic use is checking if a number is even or odd.
|
|
|
These are very useful, I'll be sure to track this for later use. Again, thank you! |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
yw |
|
|
Alright, that's all I could get out of the first page of a google search. Enough examples? |
|
|
No problem, and ignore Duel, he's just restating what I said because he's 5 % 1 percent original XD |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
"he's just restating what I said"
coming from the guy who had to google it |
|
|
I was googling EXAMPLES for him to check out, my explaination was from memory.
Now, please leave before the OP gets 100 % 101 percent annoyed because of the fact you are 100 % 101 percent annoying.
|
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
No you google'd the answer since you did not know it.
Then you put examples to cover it up. |
|
|
Took you a while to reply, had to get a calculator to figure out my equation? I'm surprised you could even work one. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
or maybe I have a life and am doing other things unlike you whose life revolves around roblox |
|
|
That's sad, you have to insult me to cover up the fact that you can't script properly. You sir, belong in OT. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
lol, you're the one who told the OP to ignore me just because you have no knowledge on scripting/programming languages |
|
|
The truth is, I replied first, not you, even though you claim you are a "regular" here.
I provided examples, and that backed it up with other sources just incase he wanted to have some practical uses.
Please, ask the OP who helped him. Do it. I dare you. |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
the only reason you were able to help is due to the fact that you google'd it, you don't understand it at all, just like everything you post on here. |
|
|
Duel you have no proof I cannot use % on my own, and you will never get any, know why? It's because I can. Now, let the thread die, "regular" |
|
LacrymaJoin Date: 2010-02-15 Post Count: 22696 |
"Duel you have no proof I cannot use % on my own"
You have no proof that you were able to before.(You had to use other people's examples)
"Now, let the thread die, "regular""
You want the thread to die because I'm right. |
|