Preventing R From Rounding

Michael picture Michael · Jul 12, 2011 · Viewed 21.9k times · Source

How do I prevent R from rounding?

For example,

> a<-893893084082902
> a
[1] 8.93893e+14

I am losing a lot of information there. I have tried signif() and it doesn't seem to do what I want.

Thanks in advance!

(This came up as a result of a student of mine trying to determine how long it would take to count to a quadrillion at a number per second)

Answer

Joshua Ulrich picture Joshua Ulrich · Jul 12, 2011

It's not rounding; it's just the default format for printing large (or small) numbers.

a <- 893893084082902
> sprintf("%f",a)
[1] "893893084082902.000000"

See the "digits" section of ?options for a global solution.