| View previous topic :: View next topic |
| 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 |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 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") |
|
| Back to top |
|
 |
smergoo Newbie

Joined: 31 Mar 2009 Posts: 4
|
Posted: Tue Apr 28, 2009 9:21 am Post subject: |
|
|
Nice one
Thank you |
|
| Back to top |
|
 |
David Super User


Joined: 24 Oct 2003 Posts: 5668 Location: Canada
|
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. |
|
| Back to top |
|
 |
Sliderule Super User


Joined: 29 May 2004 Posts: 2474 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:
- ISODD - Returns TRUE if the value is odd, or FALSE if the number is even.
- 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 |
|
 |
|