4
> x <- 1.00042589212565
> x
[1] 1.000426

If I wanted to print the exact value of x, how would I do it?

Sorry if this is a dumb question. I tried Googling for "R" and "exact" or "round" but all I get are articles about how to round.

Thank you in advance!

Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
angryavian
  • 334
  • 3
  • 9
  • If it isn't a whole number then you won't get an exact value, just an approximation. See http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f – Richie Cotton Jul 18 '13 at 14:27
  • *exactly* The only truly exact value is the 8-bytes of a mantissa/exponent encoded floating-point value. – Spacedman Jul 18 '13 at 15:06

2 Answers2

12

Globally solution during all the session

options(digits=16)
> x
[1] 1.00042589212565

or locally just for x:

sprintf("%.16f", x)
[1] "1.0004258921256499"
agstudy
  • 119,832
  • 17
  • 199
  • 261
8
print(x, digits=15)

or

format(x, digits=15)

or

sprintf("%.14f", x)
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187