OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[SOLVED] If Odd then...

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc
View previous topic :: View next topic  
Author Message
smergoo
Newbie
Newbie


Joined: 31 Mar 2009
Posts: 4

PostPosted: Tue Apr 28, 2009 8:49 am    Post subject: [SOLVED] If Odd then... Reply with quote

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
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


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

PostPosted: Tue Apr 28, 2009 9:10 am    Post subject: Reply with quote

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")
Back to top
View user's profile Send private message
smergoo
Newbie
Newbie


Joined: 31 Mar 2009
Posts: 4

PostPosted: Tue Apr 28, 2009 9:21 am    Post subject: Reply with quote

Nice one Very Happy
Thank you
Back to top
View user's profile Send private message
David
Super User
Super User


Joined: 24 Oct 2003
Posts: 5668
Location: Canada

PostPosted: Wed Apr 29, 2009 7:07 am    Post subject: Reply with quote

smergoo wrote:
Nice one Very Happy


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.
Back to top
View user's profile Send private message
Sliderule
Super User
Super User


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

PostPosted: Wed Apr 29, 2009 8:01 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Calc All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group