title: How can I accurately determine if a double is an integer?
body: <p>Specifically in Java, how can I determine if a <code>double</code> is an integer?  To clarify, I want to know how I can determine that the double does not in fact contain any fractions or decimals.</p>
  
  <p>I am concerned essentially with the nature of floating-point numbers.  The methods I thought of (and the ones I found via Google) follow basically this format:</p>
  
  <pre><code>double d = 1.0;
  if((int)d == d) {
      //do stuff
  }
  else {
      // ...
  }
  </code></pre>
  
  <p>I'm certainly no expert on floating-point numbers and how they behave, but I am under the impression that because the <code>double</code> stores only an <em>approximation</em> of the number, the <code>if()</code> conditional will only enter <em>some</em> of the time (perhaps even a <em>majority</em> of the time).  But I am looking for a method which is guaranteed to work 100% of the time, regardless of how the <code>double</code> value is stored in the system.</p>
  
  <p>Is this possible?  If so, how and why?</p>