Save-Point
How to check if the value of a number is an even or odd number? - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: How to check if the value of a number is an even or odd number? (/thread-878.html)



How to check if the value of a number is an even or odd number? - PK8 - 01-04-2010

Heya, I was wondering if there was a way I could check if the value of a number is even or odd numbered through scripting. Is there? If so, how do I do it? :o


[Resolved] How to check if the value of a number is an even or odd number? - DerVVulfman - 01-04-2010

There has gotta be a simple MACL def to handle odd/even checking. Something like:
if my_test_value.is_a?(odd_value) or something


[Resolved] How to check if the value of a number is an even or odd number? - Charlie Fleed - 01-04-2010

Code:
if number%2==0
  #even
else
  #odd
end



[Resolved] How to check if the value of a number is an even or odd number? - DerVVulfman - 01-04-2010

*Smacks forehead*
The % Remainder symbol. I totally forgot. Yep. That'll do it.


[Resolved] How to check if the value of a number is an even or odd number? - fgsfds - 01-04-2010

pwnt.
(I didn't see that coming, thought it was a trick question :l)


[Resolved] How to check if the value of a number is an even or odd number? - PK8 - 01-04-2010

Oh man, thanks Charlie. :D