title: Dividing two integers to produce a float result
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7571326/why-cant-i-return-a-double-from-two-ints-being-divided">Why can&#39;t I return a double from two ints being divided</a>  </p>
  </blockquote>
  
  
  
  <p>My C++ program is truncating the output of my integer devision even when I try and place the output into a float. How can I prevent this whilst keeping those to variables (a &amp; b) as integers?</p>
  
  <pre><code>user@box:~/c/precision$ cat precision.cpp
  #include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main()
  {
    int a = 10, b = 3;
    float ans = (a/b);
    cout&lt;&lt;fixed&lt;&lt;setprecision(3);
    cout &lt;&lt; (a/b) &lt;&lt; endl;
    cout &lt;&lt; ans &lt;&lt; endl;
    return 0;
  }
  
  user@box:~/c/precision$ g++ -o precision precision.cpp 
  user@box:~/c/precision$ ./precision 
  3
  3.000
  </code></pre>