[Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register]

Author Message
smergoo
Newbie

Joined: 31 Mar 2009
Posts: 4

 Posted: Tue Apr 28, 2009 8:49 am    Post subject: [SOLVED] If Odd then... Is there a way to make an if statement return a different values depending on if an equation's answer is even or odd?Last edited by smergoo on Tue Apr 28, 2009 9:41 am; edited 1 time in total
JohnV

Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

 Posted: Tue Apr 28, 2009 9:10 am    Post subject: Put any number in A1. Put 2 in B2. Enter this formula in another cell. =IF(MOD(A1;B1)=0;"Even number in A1";"Odd number in A1")
smergoo
Newbie

Joined: 31 Mar 2009
Posts: 4

 Posted: Tue Apr 28, 2009 9:21 am    Post subject: Nice one Thank you
David
Super User

Joined: 24 Oct 2003
Posts: 5668

Posted: Wed Apr 29, 2009 7:07 am    Post subject:

 smergoo wrote: Nice one

Yes indeed, but no separate cell is needed in this case for the constant "2" [although it is a good idea in general for future changes.]

=IF(MOD(A1;2);"odd";"even")

David.
Sliderule
Super User

Joined: 29 May 2004
Posts: 2499
Location: 3rd Rock From The Sun

Posted: Wed Apr 29, 2009 8:01 am    Post subject:

Just as an additional FYI . . . there is another Calc Function that might be of use:
1. ISODD - Returns TRUE if the value is odd, or FALSE if the number is even.
2. ISEVEN - Returns TRUE if the value is an even integer, or FALSE if the value is odd.

Therefore, the following code ( as an example ) would return the desired results:
 Code: =IF( ISODD(A1); "Odd"; "Even" )

Sliderule
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT - 8 Hours Page 1 of 1

 Jump to: Select a forum OpenOffice.org Forums----------------Setup and TroubleshootingOpenOffice.org WriterOpenOffice.org CalcOpenOffice.org ImpressOpenOffice.org DrawOpenOffice.org MathOpenOffice.org BaseOpenOffice.org Macros and APIOpenOffice.org Code Snippets Community Forums----------------General DiscussionSite Feedback
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum