title: Floating point calculation gives different results with float than with double
body: <p>I have the following line of code.</p>
  
  <pre><code>hero-&gt;onBeingHit(ENEMY_ATTACK_POINT * (1.0 - hero-&gt;getDefensePercent()));
  </code></pre>
  
  <ul>
  <li><code>void onBeingHit(int decHP)</code> method accepts integer number and updates health points.</li>
  <li><code>float getDefensePercent()</code> method is a getter method returning the defense percent of a hero.</li>
  <li><code>ENEMY_ATTACK_POINT</code> is a macro constant factor defined as <code>#define ENEMY_ATTACK_POINT 20</code>.</li>
  </ul>
  
  <p>Let's say <code>hero-&gt;getDefensePercent()</code> returns <code>0.1</code>. So the calculation is</p>
  
  <pre><code>20 * (1.0 - 0.1)  =  20 * (0.9)  =  18
  </code></pre>
  
  <p>Whenever I tried it with the following code (no <code>f</code> appending <code>1.0</code>)</p>
  
  <pre><code>hero-&gt;onBeingHit(ENEMY_ATTACK_POINT * (1.0 - hero-&gt;getDefensePercent()));
  </code></pre>
  
  <p>I got <strong>17</strong>.</p>
  
  <p>But for the following code (<code>f</code> appended after <code>1.0</code>)</p>
  
  <pre><code>hero-&gt;onBeingHit(ENEMY_ATTACK_POINT * (1.0f - hero-&gt;getDefensePercent()));
  </code></pre>
  
  <p>I got <strong>18</strong>.</p>
  
  <p>What's going on? Is <code>f</code> significant to have at all although <code>hero-&gt;getDefensePercent()</code> is already in float?</p>