title: java double calculation
body: <p>I understand that computer can not represent non-integral numbers precisely. so when I add 2 doubles in java for example:</p>
  
  <pre><code>724.64d + 1000d
  </code></pre>
  
  <p>the console print out  1724.6399999999999</p>
  
  <p>but why for <code>724.64d + 100d</code> and <code>724.64d + 10000d</code></p>
  
  <p>the console print out 824.64 and 10724.64 separately?</p>
  
  <p>is there a way to know at what condition when I add the 2 doubles, the sum is the exact number ?</p>
  
  <p>The reason why I ask is because that our old program use double to do calculation. and use double comparison to validate the numbers.
  for example: let us say the total is <code>1849.64</code>, all the inputs amounts added up must be equals to total which is <code>1849.64</code></p>
  
  <pre><code>input 1: 724.64
  input 2: 1125
  </code></pre>
  
  <p>will not work, because the sum will be 1849.6399999999999</p>
  
  <p>but if we input like this below will work, and the sum is 1849.64</p>
  
  <pre><code>input 1: 24.64
  input 2: 1825
  </code></pre>
  
  <p>so how to find those combinations that work?
  Note, I do not have access to this specific very old program. when the validation failed, we have to manually find a walk around like the second inputs combination.
  Thanks.</p>