Skip to contents

This function addresses some of the conflicts of rounding in R, especially when trying to round up.

Usage

acled_rounding(num, digits = 0)

Arguments

num

int. This is the number we are trying to round.

digits

int. Where do we want to round up. It accepts 0 (whole number), 1 (tenth place), 2 (hundredths), etc.

Details

This function is meant to address the problem of rounding in R where the approach is always round to even. The function is meant to round things following the simple rule. If the decimal is 5+ then round up, if not round down. With the 'digits' argument, one can set up the specificity of the rounding, 0= whole number, 1 = tenth place, 2=hundreds place, and so on.

Examples

x1 <- 1.569
x2 <- 104.530
x3 <- 54.430
x4 <- 205.49999
acled_rounding(x1)
#> [1] 2
acled_rounding(x2)
#> [1] 105
acled_rounding(x3)
#> [1] 54
acled_rounding(x4)
#> [1] 205