Skip to content

Commit

Permalink
correct formula for rounding down in vignette
Browse files Browse the repository at this point in the history
  • Loading branch information
lhdjung committed Feb 16, 2024
1 parent 6dc7b69 commit 7d29655
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions R/round.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions vignettes/rounding-in-detail.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7d29655

Please sign in to comment.