0

Possible Duplicate:
Why are these numbers not equal?

I was trying to round a number. The following are fine:

floor(3)
[1] 3

however:

floor (0.6 / 0.2)
[1] 2

or

 x <- 0.6 / 0.2
 floor (x) 
[1] 2

Why not 3 ?

Edit:

I am not concern with mechanics rather I want it be consistently rounded to 3, so that my function work properly.

Edit2:

I was not thinking something complex (as in the following discussion and not trying to prove as if to prove R is not doing its work), with help of suggestion below particularly from Matthew Lundberg, I could figure out a way through, may be some like me find useful. So this is what I did -

x1 <- 0.6 *100
x2 <- 0.2 *100
floor (x1/x2)
[1] 3
Community
  • 1
  • 1
rdorlearn
  • 641
  • 4
  • 14
  • My question was not why ? rather how I can make it work see my edit – rdorlearn Dec 17 '12 at 04:32
  • 3
    As written, you can't make it work without breaking other cases. Determine why you need a ratio of inexact values, and change that. – Matthew Lundberg Dec 17 '12 at 04:35
  • This is not an R question. The priciples apply to any language where there is a trunc or floor function, i.e. pretty much any computer language. If you are having trouble with (extremely basic) concepts in numerical analysis, then ... do your homework. – IRTFM Dec 17 '12 at 04:41
  • thank you all for the comments, as DWin said I might need some homework ... – rdorlearn Dec 17 '12 at 04:56

0 Answers0