Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm assigning the value below in R to var x which I read from a file and when I prints it, it shows a double format. I want to be able to store this long number without decimal because when I do a REST post the data gets posted as double. I've tried as.character(x), but then when doing POST to REST API it is treated as a string. Is there any way to keep this value as Long and not decimal?

x <- 1426643216897

print(x)
[1] 1.426643e+12

Thranks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
129 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'd suggest using quote=FALSE in the print function if working with characters that you do not want enclosed. Since print also accepts a digits argument you can go either way:

> print(as.character(x), quote=FALSE)
[1] 1426643216897
> print(x,  digits=20)
[1] 1426643216897

Versus:

> print(as.character(x) )
[1] "1426643216897"

There is no R long-integer mode. You should understand that numbers with more than 9 base-10 digits are being "stored as decimals", i.e. stored with abscissa+mantissa, but the apparent increase of integer length is accomplished through printing of the exact conversion of the abscissa of the "double" to base-10 representation without the decimal point. Notice what happens if you explicitly attempt to "store as integer":

> x <- 1426643216897L
Warning message:
non-integer value 1426643216897L qualified with L; using numeric value 

If you needed to store a number with greater length than the 53 binary digits could handle, you would need to go with character storage, and then use the quote=FALSE option or use cat for output:

>  cat("test")
test

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...