# How to check if a var is a decimal?

**URL:** <https://forum.kirupa.com/t/how-to-check-if-a-var-is-a-decimal/14605>\
**Category:** Uncategorized\
**Created:** [February 28, 2003, 6:21am UTC](https://forum.kirupa.com/t/how-to-check-if-a-var-is-a-decimal/14605 "2003-02-28T06:21:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindfriction](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mindfriction/32/172_2.png) [@mindfriction](https://forum.kirupa.com/u/mindfriction)\
**Post date:** [February 28, 2003, 6:21am UTC](https://forum.kirupa.com/t/how-to-check-if-a-var-is-a-decimal/14605/1 "2003-02-28T06:21:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 28, 2003, 7:08am UTC](https://forum.kirupa.com/t/how-to-check-if-a-var-is-a-decimal/14605/2 "2003-02-28T07:08:13Z")

</div>

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

```auto

theNumb=3;

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 28, 2003, 1:54pm UTC](https://forum.kirupa.com/t/how-to-check-if-a-var-is-a-decimal/14605/3 "2003-02-28T13:54:13Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 28, 2003, 5:18pm UTC](https://forum.kirupa.com/t/how-to-check-if-a-var-is-a-decimal/14605/4 "2003-02-28T17:18:26Z")

</div>

Thanks, 🙂

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 😕

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