[R] QUESTION ON ROUNDING

Duncan Murdoch murdoch.duncan at gmail.com
Thu Mar 28 20:07:01 CET 2013


On 28/03/2013 2:21 PM, Andras Farkas wrote:
> Dear All,
>   
> wonder if you have a thought on the following: I am using the round(x,digits=3) command, but some of my values come out as: 0.07099999999999999 AND 0.06900000000000001. Any thoughts on why this maty be happening or how to eliminate the problem?
>   

You are confusing rounding and string conversion.  I imagine

0.07099999999999999

is what you get when you print 0.071 with 17 digits, because 0.071 can't 
be represented exactly in the double precision floating point that R 
uses.  If you want to format it for display, then use format() (or 
sprintf(), or one of the other formatting functions), don't use round().

Duncan Murdoch



More information about the R-help mailing list