Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R rounding explanation

Tags:

r

can any one please explain why this gives different outputs?

round(1.49999999999999)
1


round(1.4999999999999999)
2

I have read the round documentation but it does not mention anything about it there. I know that R represents numbers in binary form, but why does adding two extra 9's changes the result?

Thanks.

like image 716
user557240 Avatar asked Oct 28 '11 15:10

user557240


1 Answers

1.4999999999999999 can't be represented internally, so it gets rounded to 1.5.

Now, when you apply round(), the result is 2.

like image 146
Dennis Avatar answered Oct 12 '22 11:10

Dennis