title: Accurate percentage in C++
body: <p>Given 2 numbers, where <code>A &lt;= B</code> say for example <code>A = 9</code> and <code>B = 10</code>, I am trying to get the percentage of how smaller A is compared to B. I need to have the percentage as an <code>int</code> e.g. if the result is 10.00% The <code>int</code> should be 1000.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>int A = 9;
  int B = 10;
  
  int percentage = (((1 - (double)A/B) / 0.01)) * 100;
  </code></pre>
  
  <p>My code returns 999 instead of 1000. Some precision related to the usage of <code>double</code> is lost.</p>
  
  <p>Is there a way to avoid losing precision in my case?</p>