Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Lets say I have an integer
If even number then round down to an odd number.
If odd then keep the number.
eg. x = 888
I want to round this down to an odd number. 887
Thank you.
Solved! Go to Solution.
Should this also apply to zero and negative integers?
At least that's what your description demands and what Terry's solution provides.
BTW, if your inputs are only integers, you may also omit the "floor" functions:
If you intend to use the function for positive integers only, you may also try this:
Note the capital "R" in "Round". You see that the result for negative odd inputs is 'wrong'.
In case you rather intend to round "in the direction of zero" (basically apply the rounding to the absolute value of the input) you may use
Of course you get the same result with
And at last here is an alternative function doing exactly what you demanded (and what Terry's function also provides)