0

If I sum 0.1, 10 times in R why does it not equal 1?

e.g

0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 == 1

returns

FALSE

However

0.1 * 10 ==1

returns

TRUE

Can anyone explain this behavior?

user124123
  • 1,642
  • 7
  • 30
  • 50
  • 1
    I don't know if it's related here but whenever there is a question related to floating point it is somehow always linked to https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal – Ronak Shah Jul 12 '19 at 04:42
  • and as mentioned `all.equal(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1,1)` gives `#[1] TRUE` – Ronak Shah Jul 12 '19 at 04:44

0 Answers0