Why would Ruby fail equality on 2 floats that appear the same?

Posted by btelles on Stack Overflow See other posts from Stack Overflow or by btelles
Published on 2010-04-07T20:26:11Z Indexed on 2010/04/07 20:33 UTC
Read the original article Hit count: 318

Filed under:
|

Hi there, I have a calculation that generates what appears to be the Float 22.23, and a literal 22.23 like so:

some_object.total => 22.23
some_object.total.class => Float

22.23 => 22.23
22.23.class => Float

But for some reason, the following is false:

some_object.total == 22.23 ? true : false

Wacky, right?

Is there some kind of precision mechanism being used that maybe isn't completely transparent through the some_object.total call?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails