Thread: Odd or Even
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Odd or Even

Strange, 1.3 MOD 2 also returns 1 which the previous poster called as Odd,
but you didn't seek to point that out?

And if non-integer values need to be catered for it is easily extended

Public Function IsOdd(Val)
If Val \ 1 < Val Then
IsOdd = "Invalid value"
Else
IsOdd = (Val \ 2) * 2 < Val
End If
End Function



Bob


"JE McGimpsey" wrote in message
...
Note that this returns true for non-integer values (which are neither
odd nor even).

OTOH, the ATP's ISODD function truncates the number first, so

=ISODD(1.9) === FALSE
=ISODD(2.9) === TRUE

which seems worse to me.


In article ,
"Bob Phillips" wrote:

Public Function IsOdd(Val) As Boolean
IsOdd = (Val \ 2) * 2 < Val
End Function