0

I need a sequence, converted to strings, of simple fractional numbers, as in

"72.05", "71.95", "71.85", ...

Why is it that R uses such bizarre internal representations that you get the below results? - Kind of a throw-back to the very early days of pocket calculators, or am I missing something important on the way R does arithmetic?

paste(seq(72.05, -53.95, by = -0.1))[621:626]

results in very unexpected

"10.05" "9.95" "9.84999999999999" "9.74999999999999" "9.64999999999999" "9.55"

(I can certainly manually correct this particular output, however I start to doubt internal precisions of R in a very fundamental way...)

(R version 3.2.2 (2015-08-14), 64bit, on Windows)

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Adrian
  • 21
  • 2
    I would guess [this is somewhat related](http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal), which isn't really R specific, [just floating points is general](http://floating-point-gui.de/basic/) – David Arenburg Feb 21 '16 at 13:01
  • 1
    [Another relevant thread](http://r.789695.n4.nabble.com/Rounding-error-in-seq-td904967.html) – Henrik Feb 21 '16 at 13:28

0 Answers0