How to check if a var is a decimal?

Hi,

I need to check whether a varaible is an odd number, as I alternate which part of the movie I play.

something like…

if(i=oddNumb)
{
gotoAndPlay(…)
}
else
{
gotoAndPlay(…)
}

I was thinking if i could take the value of the variable divide it by 2, and then check whether the answer is a decimal and then I could tell if it was an odd number., But Im not sure how to do this even.

Your help appreciated

Oh well after a little while Iactually found a way: :smiley:


theNumb=3;

ans = theNumb/2;
trace(ans);
check = Math.round(ans);
trace(check);
if(check == ans)
{
	trace("is EVEN");
	
}
else
{
	trace("is ODD");
}

There’s an easier and shorter way to determine whether a variable is odd or even with the modulo operator:

if a number is even, it’s possible to divide it by 2 (the rest equals 0) so you could create a little prototype:

Number.prototype.isEven=function(){
  return !(this%2) ;
}

this%2 returns 0 is the number is even and 1 if it’s odd, so we take the opposite with !.

Cheers.

Thanks, :slight_smile:

Its actually for the same flash which Im trying to use prototypes in (my other recent posting) , but alas Ive almost given up on the prototyping as I dont seem to completely understand it :confused:

(other posting re prototypes)
http://www.kirupaforum.com/showthread.php?s=&threadid=6636