How to convert a 20-digit character to a numeric

I have four 20-digit characters.
I want to convert characters to numeric. I just converted using as.numeric function.
But the four characters are the same.
Why?
I need a numeric one. Is there any way?

tmp <- c("11240690100051000001", "11240690100051000002", "11240690100051000003", "11240690100051000004")
tmp1 <- as.numeric(tmp)

tmp1[1] == tmp1[2]
[1] TRUE
tmp1[1] == tmp1[3]
[1] TRUE
tmp1[1] == tmp1[4]
[1] TRUE
+4
source share
1 answer

You can use the package Rmpfr:

tmp <- c("11240690100051000001", 
 "11240690100051000002", "11240690100051000003", 
"11240690100051000004")
library("Rmpfr")
as.bigz(tmp)
##  Big Integer ('bigz') object of length 4:
## [1] 11240690100051000001 11240690100051000002 11240690100051000003
## [4] 11240690100051000004

... but this can seriously limit what you can subsequently do with these values. More context on the question of why you need these numbers or what you plan to do with them may lead to more useful answers ...

+3
source

All Articles