In R software
a <- 123456789123456789123456789
sprintf("%27f",a)
#[1] "123456789123456791337762816.000000"
I got the wrong answer. I want exact a value.
Why is the system showing the wrong value of a?
In R software
a <- 123456789123456789123456789
sprintf("%27f",a)
#[1] "123456789123456791337762816.000000"
I got the wrong answer. I want exact a value.
Why is the system showing the wrong value of a?
The reason you're not getting your exact value of
ais that R is storing it as a double instead of as an integer. Becauseais very large, there is some rounding that takes place when you assigna.Normally to store things as integers you would use
Lat the end of the numbers; something like:However your number is too large for a standard integer in R, and you're forced to use the double representation:
You will need multiple precision to exactly store an integer this large. One option would be the
gmppackage:Other options for multi-precision arithmetic are available under the "Multi-Precision Arithmetic and Symbolic Mathematics" subheading of the numerical mathematics CRAN task view.