rounding: Rounding of numbers

roundingR Documentation

Rounding of numbers

Description

Round a number to the nearest value.

Usage

integer_round(x, upper5 = TRUE)
decimal_floor(x, digits = 1)
decimal_ceiling(x, digits = 1)
integer_floor(x, base=10)
integer_ceiling(x, base=10)

Arguments

x

A numeric vector.

upper5

Logical value that regulates the rounding in presence of the decimal .5.

digits

Integer indicating the number of decimal places to consider.

base

Integer value to use as step in rounding. The x values will be rounded to the nearest lower/upper base value.

Details

integer_round rounds a decimal number to the nearest integer. When the decimal is exactly .5, the number is rounded to the upper integer (upper5 = T). The opposite behavior is obtained when upper5 = F.

decimal_floor and decimal_ceiling round a decimal number to the nearest decimal digit, specified by digits.

integer_floor and integer_ceiling round a number to the nearest integer value specified by base.

See Also

round

Examples

x <- c(8.87, 9.26, 10.5, 11.5, 12.5)
integer_round(x)
integer_round(x, upper5=FALSE)
round(x) # round has a different behavior for 10.5 and 11.5
decimal_floor(x)
decimal_ceiling(x)
x <- c(1, 9, 24, 32, 59)
integer_floor(x)
integer_ceiling(x)
integer_ceiling(x, base=5)

DavideMassidda/testing documentation built on Oct. 12, 2023, 4:32 p.m.