|
| 05 Jul 2014 06:28 AM |
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. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:31 AM |
Title Fix: Use of % / Modulus? |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:36 AM |
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 |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 04:23 PM |
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? |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 04:29 PM |
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) |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 04:32 PM |
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. :) |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 04:40 PM |
For a few more practical uses;
http://stackoverflow.com/questions/2609315/recognizing-when-to-use-the-modulus-operator |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:24 PM |
Then, not much more information, but this has more example;
http://stackoverflow.com/questions/3589976/what-are-the-practical-uses-of-modulus-in-programming |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:28 PM |
The examples are in C# but there's here;
http://watchhogstories.wordpress.com/2008/08/11/coding-practices-the-modulus-operator/ |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:31 PM |
You'll need it in many algorithms. Basic use is checking if a number is even or odd.
|
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:31 PM |
| These are very useful, I'll be sure to track this for later use. Again, thank you! |
|
|
| Report Abuse |
|
|
| |
|
|
| 05 Jul 2014 05:32 PM |
| Alright, that's all I could get out of the first page of a google search. Enough examples? |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:34 PM |
| No problem, and ignore Duel, he's just restating what I said because he's 5 % 1 percent original XD |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:34 PM |
"he's just restating what I said"
coming from the guy who had to google it |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:43 PM |
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.
|
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:56 PM |
No you google'd the answer since you did not know it. Then you put examples to cover it up. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 05:59 PM |
| Took you a while to reply, had to get a calculator to figure out my equation? I'm surprised you could even work one. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:01 PM |
| or maybe I have a life and am doing other things unlike you whose life revolves around roblox |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:03 PM |
| That's sad, you have to insult me to cover up the fact that you can't script properly. You sir, belong in OT. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:04 PM |
| lol, you're the one who told the OP to ignore me just because you have no knowledge on scripting/programming languages |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:07 PM |
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. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:08 PM |
| 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. |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:11 PM |
| 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" |
|
|
| Report Abuse |
|
|
|
| 05 Jul 2014 06:13 PM |
"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. |
|
|
| Report Abuse |
|
|