Note also that if you wish to include 0 and negative numbers, and your
intent is to truncate to 1 digit towards 0, then you must of course check
for 0 separately and modify what I suggested for x != 0 to:
k <- floor(log10(abs(x)))
ifelse(x <0, ceiling(x*10^(-k)), floor(x*10^(-k))) *10^k
Note that
This is *not* "rounding down."
But this should do it I think:
## (see ?floor)
x <- 3.896e09
k <- floor(log10(x))
> floor(x*10^(-k))*10^k
[1] 3e+09
There may be even slicker ways, but this is as slick as I can muster...
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that
Hello,
How can I round down numeric values with decimals? For example,
> signif(3.896037e+09, digits = 1)
[1] 4e+09
The expected result is 3e+09 (and not 4e+09).
> signif(8.68542378e-10, digits = 1)
[1] 9e-10
The expected result is 8e-10 (and not 9e-10).
Thank you very much for
3 matches
Mail list logo