Reputation: 41
I'm looking for a way to convert decimals to other bases in R. The function dec2base
from the oro.dicom
package only works for integers (as stated in its help file):
> dec2base(1.559,9)
[1] "1"
Whereas 1.559 in base 9 should be 1.5024, and I was wondering if there is another method.
Upvotes: 4
Views: 1427
Reputation: 226881
The Rmpfr
package can do arbitrary-precision arithmetic and base conversion:
library(Rmpfr)
x <- mpfr(1.559, precBits = 64, base = 10) ## base = 10 is default
b9 <- as.numeric(format(x, base = 9))
print(b9)
## 1.502453
Upvotes: 1
Reputation: 21630
I think that you would be able to multiply the number by the number of non zero decimal places and undo the operation on the backend of the dec2base command.
Upvotes: 0