This is one of those things that seems so obvious that you never really think about how you’d do it.
Given a number, we immediately think that somehow we should be able to use the whole ‘divisible by 2’ thing to our advantage… and as it turns out, that’s basically it. In order to know if a number is ‘even’ or ‘odd’, we divide by and 2 and if there’s a remainder, it’s odd and if there’s no remainder the number is even. What you need is a way of testing for a remainder after doing some division and that’s the job of a math function called Mod(). Short for modulo operator (explained here on Wiki).
The Mod() function is used to divide one number by another and return the remainder. The Mod() function is applied to the number in question and the second number is set as two for our purposes. Then you test to make sure that if the remainder is zero, then the number is even. (if you were wanting to know if a number is evenly divisible by 3, you’d use a 3 and so on)
example:
Mod ( numberToTest ; 2 )
As an IF calc, it would look like this… and would return the word ‘even’ or ‘odd’.
example:
If ( Mod( numberToTest ; 2 ) ≠ 0, “odd”, “even”)
In Filemaker, you’d put a variable or a field reference where ‘numberToTest’ is in the example. In practice, this would be used to branch a script based on the ‘odd’ or ‘even’ result of the calculation.
To make this even easier to use, a developer might create a custom function called isEven() and results in true when passed a value that’s even.
I didn’t see one at Brian Dennings Custom functions site, but here’s one that’s close (Even Odd Week Today) whose job is to determine is today is in an even or odd week.
Have fun with that… see you next time.
Leave a Reply