multiples of a number in Flash
- Started
- Last post
- 8 Responses
- mr_flaco
Im searching for an algorithm that will check if a number is a multiple of another number (my variable) without comparing to an array. Does anyone have one?
- phirschybar0
You can use the % operator. Which gives you the remainder of an operation. So...
10 % 3 = 1
and 9 % 3 = 0therefore, if you get 0, your number is a multiple.
Got it?
- mr_flaco0
so...
if I say
if (x%y==0){
//script..
}right?
- phirschybar0
yes. I almost positive that % is the correct syntax for Actionscript. You might want to check this. However, even if it is something else, the operator you're looking for definitely exists in Actionscript
- mr_flaco0
I'll check it. Thanks so much!
- mr_flaco0
hmmm...
z=x%y;
always seems to return x if y is greater than x, zero if it is lower.
- phirschybar0
I just checked my Actionscript reference.
X % Y will give you the remainder of X/Y. and thats that.
- mr_flaco0
Im not finding that to be true -
x=4;
y=16;
z=x%y;
n=x/y;z returns 4
n returns .25What am I missing? Forgive me, I'm just trying to get it.
- mr_flaco0
oops - my syntax was wrong...it works.