diff --git a/R/round.R b/R/round.R index 7b4809d..82be1ef 100644 --- a/R/round.R +++ b/R/round.R @@ -114,6 +114,10 @@ round_up_from <- function(x, digits = 0L, threshold, symmetric = FALSE) { #' @rdname rounding-common #' @export +# Note that this implementation is slightly different from the formula for +# rounding down in the "Rounding in detail" article. However, this is only for +# performance reasons, and the results are equivalent. + round_down_from <- function(x, digits = 0L, threshold, symmetric = FALSE) { p10 <- 10 ^ digits diff --git a/vignettes/rounding-in-detail.Rmd b/vignettes/rounding-in-detail.Rmd index a04962f..9f057e4 100644 --- a/vignettes/rounding-in-detail.Rmd +++ b/vignettes/rounding-in-detail.Rmd @@ -94,10 +94,10 @@ $$ where $x$ is the number to be rounded, $d$ is the number of decimal places to which $x$ should be rounded, and $t$ is the threshold for rounding up (e.g., $t = 5$ for rounding up from 5). Note that $\lfloor n \rfloor$ floors a number $n$, and $\lceil n \rceil$ ceils it. -Rounding down works accordingly: +Rounding down works accordingly. Note that $+$ and $-$ are reversed here: $$ -\frac{\lceil x(10^d) -1 - \frac{t}{10} \rceil}{10^d} +\frac{\lceil x(10^d) - 1 + \frac{t}{10} \rceil}{10^d} $$ ### To even (base R)