Issue comparing doubles <p>This simple if-comparison is not working, and i'm not sure why.</p> <p>Code:</p> <pre><code>public abstract class Button extends Drawable_object { ... @Override public void update() { super.update(); mouseOver_last = mouseOver; double mx = Game_logic.get_mouse_x(); double my = Game_logic.get_mouse_y(); //the not working statement check: if ((mx &lt;= x + ((double)width / 2))&amp;&amp; (mx &gt;= x - ((double)width / 2))&amp;&amp; (my &gt;= y - ((double)height / 2))&amp;&amp; (my &lt;= y + ((double)height / 2))) { mouseOver = true;} else mouseOver = false; .... } </code></pre> <p>Whilst Game_logic.get_mouse_x() and y are static methods:</p> <pre><code>public class Game_logic { ... public static double get_mouse_x() { return mouse_x; } public static double get_mouse_y() { return mouse_y; } } </code></pre> <p>And those are set by Mouse adapaer in my main run class:</p> <pre><code> public Board() throws IOException, URISyntaxException { ... private class MAdapter2 extends MouseAdapter { @Override public void mouseMoved(MouseEvent e) { Game_logic.set_mouse_x(e.getX()); Game_logic.set_mouse_y(e.getY()); } } </code></pre> <p>The thing is, when I draw on screen x - width / 2, mx and x + width / 2 (same with y), holding mouse at my desired position looks like statement must be true, but <code>mouseOver</code> is still false. How do i fix that?</p>