Rounding a number x to the nearest integer requires some tie-breaking
rule for those cases when x is exactly half-way between two integers,
that is, when the fraction part of x is exactly 0.5. The
round_half_up()
function implements a tie-breaking rule that
consistently rounds half units upward. Although this creates a slight
bias toward larger rounded outputs, it is widely used in many disciplines.
The round_half_even()
function breaks ties by rounding to the nearest
even unit.
round_half_up(rspec) round_half_even(rspec)
rspec | a |
---|
an object of class rounding_specification
.
Other rounding helpers:
round_using_magnitude()
#> [1] 0#> [1] 2#> [1] 2# make rspec that rounds up rspec <- round_half_up(round_spec()) rspec <- round_using_decimal(rspec, digits = 0) # check table_value(0.5, rspec) # --> 1#> [1] "1"#> [1] "2"#> [1] "3"# make rspec that rounds even rspec <- round_half_even(round_spec()) rspec <- round_using_decimal(rspec, digits = 0) # check table_value(0.5, rspec) # --> 0#> [1] "0"#> [1] "2"#> [1] "2"