1

I'm doing a simple subtraction between 2 decimals in ruby, but am getting a suprisingly odd result. If I run the following in IRB, I would have expected to get 0.011. I realize I can do (0.942 - 0.931).round(3) to get the answer I'm expecting, but am wondering why ruby returns the result it does.

 1.9.3-p551 :004 > (0.942 - 0.931)
 => 0.010999999999999899
d-coded
  • 413
  • 3
  • 9
  • 1
    It is not a bad thing to have a duplicate question - it may help catch other users looking for the same answers, whilst answering yours (hopefully). Also recommended: http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html – Neil Slater Nov 19 '15 at 21:47
  • That does explain it. Just didn't come across that when searching. Thanks Neil. – d-coded Nov 19 '15 at 22:01

0 Answers0