Even and Odd numbers in Variables

I was wondering if there is a way to set an If/Then command that could determine whether my current variable is an even or an odd number.

Basically, I wanna tell KM that if my variable is an odd number, do this. Else, do that.

Any ideas?

Thanks.

Offhand, I can think of two ways to do this. One, use a regular expression to check if the last digit of the variable is an odd number:

Odd

image

Even

image

Or, just to be mathematically sure, use a simple modulo calculation to verify if the remainder of the number divided by 2 is 1 or not:

Odd

image

Even

image

3 Likes

Unless I am missing something, the last test (Even) should be TestVariable MOD 2 = 0 (or the setting should be "none of the follow conditions are true".

But yes, that is what I would use, the calculation condition and the MOD operator.

2 Likes

That worked!!!
You're the best!

thank you so much :smile:

1 Like