This question does not duplicate Round up from 0.5. I am looking for different behavior. I want -0.5 to round up to 0, and 0.5 to round up to 1. This behavior needs to work consistently for all numbers with decimal values of -0.5 or 0.5.
Here is the result I want:
c(-0.7, -0.5, 0, 0.2, 0.5)
[1] -1 0 0 0 1
With round I get this:
> round(c(-0.7, -0.5, 0, 0.2, 0.5))
[1] -1 0 0 0 0
With ceiling I get this:
> ceiling(c(-0.7, -0.5, 0, 0.2, 0.5))
[1] 0 0 0 1 1
janitor::round_half_up() doesn't seem to work on negative numbers.
> round_half_up(c(-0.7, -0.5, 0, 0.2, 0.5))
[1] -1 -1 0 0 1
floor()
obviously doesn't do what I'm looking for, and neither does the round2()
function that is sometimes suggested for other questions about rounding.
Thank you!