0

I have been playing around with this command for a while and cannot seem to make it work the way I would like it to. I would like format to give me the full list of numbers as a text without any rounding even when the whole number portion is large. For example:

format(2290000000000000000.000081 , scientific=FALSE)
[1] "2290000000000000000"

While what I want returned is:

"2290000000000000000.000081"
Francis Smart
  • 3,875
  • 6
  • 32
  • 58
  • 1
    This isn't a problem in `format`, it has to do with the way R prints numbers. The number is changed before it even gets processed in `format`. I'm searching for a solution. – Rich Scriven Sep 14 '14 at 01:35
  • 1
    By the way, you can turn off scientific notation with `options(scipen = 999)` – Rich Scriven Sep 14 '14 at 01:38
  • Base R has no way to represent the number "2290000000000000000.000081" with exact precision. It is not a value you can store exactly in a double. If you do `a<-2290000000000000000.000081`, some loss of information occurs. Maybe try reading [why aren't these numbers equal](http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) for more information. – MrFlick Sep 14 '14 at 01:39
  • If you do not want to do any further calculations on it, you can store it as: a = "2290000000000000000.000081" – rnso Sep 14 '14 at 07:25

1 Answers1

1

As noted, you can't store that number exactly using double precision. You'll need to use multiple-precision floating point numbers.

library(Rmpfr)
mpfr("2290000000000000000.000081", precBits=85)
## 1 'mpfr' number of precision  85   bits 
## [1] 2290000000000000000.000081
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360