title: Cast double to int, but only if exact conversion
body: <p>I'm getting a value of type <code>double</code> from an API which, in my specific case, should always return a whole number in a range well within <code>int</code>'s — any non-whole number will mean something went very wrong inside that API call. I do want to know when this happens.</p>
  
  <p>I know I can do a post-conversion check like, let say:</p>
  
  <pre><code>double value = …;
  int whole_number = (int) value;
  if(value != whole_number) throw …;
  </code></pre>
  
  <p>Is there any shorter idiom to "Convert a <code>double</code> to <code>int</code> only if it is an exact conversion, and raise an exception if not"?</p>