Your something
is a double
, and you have correctly identified that in the line
if (something == 0)
we have a double
on the left-hand side (lhs) and an int
on the right-hand side (rhs).
But now it seems like you think the lhs will be converted to an int
, and then the ==
sign will compare two integers. That's not what happens. The conversion from double
to int
is explicit and can not happen "automatically".
Instead, the opposite happens. The rhs is converted to double
, and then the ==
sign becomes an equality test between two doubles. This conversion is implicit (automatic).
It is considered better (by some) to write
if (something == 0.0)
or
if (something == 0d)
because then it's immediate that you're comparing two doubles. However, that's just a matter of style and readability because the compiler will do the same thing in any case.
It's also relevant, in some cases, to introduce a "tolerance" like in Jon Skeet's answer, but that tolerance would be a double
too. It could of course be 1.0
if you wanted, but it does not have to be [the least strictly positive] integer.