title: Why do my float values lose precision and drop decimals? Example code below
body: <p>I have never used floats really that much before and the current project I am working on requires them. I'm getting weird issues that I learned about years ago but have forgotten why this happens.</p>
  
  <p>My results after multiplying or adding floats aren't what they're supposed to be.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>void main ()
  {
      //Example 1 - ERROR
      float a=16937.6;
      float b=112918;
      float total=b+a;
      cout&lt;&lt;total&lt;&lt;endl; //Outputs 129896 - rounds up and loses decimal (129855.6)
  
      //Example 2 - Error
      float c=247.82;
      float d=9995.2;
      float total2=c+d;
      cout&lt;&lt;total2&lt;&lt;endl; //Outputs 10243 - loses all decimals (10243.02)
      system ("pause");
  
  }
  </code></pre>