[R] Rounding?

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Mon Jun 11 16:56:52 CEST 2007


jim holtman wrote:
> your number 6.6500000000000001 is to large to fit in a floating point
> number.  It takes 56 bits and there are only 54 in a real number so the
> system see it as 6.65 and does the rounding to an even digit; 6.6
>
> 6.650000000000001 does fit into a real number (takes 54 bits) and this will
> now round to 6.7
>
>   
Actually, a bit more insidious than that because 6.65 does not have an
exact binary representation. Hence

> round(66.5)
[1] 66
> round(6.65,1)
[1] 6.7
> round(0.665,2)
[1] 0.66

Notice that these are from Linux and differ from what you get on Windows.

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list