test for whole number

gcheg
06-10-2002, 02:56 AM
I'm trying to test wether a variable that is divided by 2 is a whole number or not. What I mean is if you divide 7 by 2 you get 3.5 - I need to be able catch it if the result is not a whole number

hershymoo
06-10-2002, 03:38 AM
how bout on the original number you just do
<code>
if (originalNumber % 2 == 0 )
'ok so the original number was even
else
'orginal number was odd
</code>

Road Runner
06-10-2002, 03:52 AM
yes hershymoo answer is the best way of finding if a number is divisible by 2

Just incase you dont know what Mod(%) means

4%2 = 0 (2 into 4 goes twice remainder 0. so anwser = 0)

2%4 = 2 (4 into 2 goes zero remainder 2. so answer = 2)

So to sum up
if any number % 2 = 0 then the number is even

Shane

gcheg
06-10-2002, 06:38 AM
Thank you both very much. I was too worried about the result to think about what I was starting with.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum