no infinite loop when d <= 0,
while mainting the functionality for d>0.
round_digit <- function (d) {
if (d > 1) {
round(d)
} else {
round(d, -as.integer(floor(log10(abs(d)))))
}
}
It rounds to digits=0 if d>1
and for d<1, it rounds to the first decimal different from 0. - Like the original code.
But especially it doesn't end up in an endless loop for d = 0 or d < 0!
no infinite loop when d <= 0, while mainting the functionality for d>0.
It rounds to
digits=0
ifd>1
and ford<1
, it rounds to the first decimal different from0
. - Like the original code. But especially it doesn't end up in an endless loop ford = 0
ord < 0
!