An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20130328/0220dcb6/attachment.pl>
QUESTION ON ROUNDING
3 messages · Andras Farkas, R. Michael Weylandt, Duncan Murdoch
On Thu, Mar 28, 2013 at 6:21 PM, Andras Farkas <motyocska at yahoo.com> 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?
I'd guess you've played with the default digits for print() (perhaps via options) but a reproducible example would be terribly lovely. MW
apreciate the help,
Andras
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
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