Particularly when creating tables, it is often desirable to keep all numbers to the same width. round() and similar functions drop trailing zeros - this version keeps them and thus rounds 1.201 to 1.20 rather than 1.2 when 2 digits are requested.

round_(x, digits = 2)

Arguments

x

Numeric vector to be rounded

digits

Number of significant digits

Value

Character vector of rounded values, with trailing zeroes as needed to show digits figures after the decimal point

Details

By default, uses "round half to even" (banker's rounding), but the rounding method can be changed via the timesaveR.round_method option (see Details).

The rounding method is controlled by the timesaveR.round_method option:

  • "to_even" (default): Round half to even (banker's rounding)

  • "default": Standard R rounding (round half away from zero)

Set via options(timesaveR.round_method = "default") to change for your session.

Examples

round_(1.201, 2)
#> [1] "1.20"
round_(c(1.2, 3.456, 7.8), digits = 2)
#> [1] "1.20" "3.46" "7.80"