Rounding and displaying exact value
<p>Guys I have a question:</p>

<p><code>39268112/50000000*4</code> is <strong>exactly</strong> <code>3.14144896</code></p>

<p>But when i write a code in c++ as such:</p>

<pre><code>#include&lt;iostream.h&gt;
using namespace std;
int main()
{
   int a = 39268112;
   int b = 50000000;
   cout &lt;&lt; (double)a / (double)b * 4;
}
</code></pre>

<blockquote>
  <p>But, I get <strong>3.14145</strong>.</p>
</blockquote>

<p>This is not the exact value. <br><br>
<strong>So my question is:</strong> </p>

<blockquote>
  <p>how can i always display the exact value of a <code>double</code> division?</p>
</blockquote>

<p>EDIT: I am aware of the setprecision option, the problem here is just, that I have to know the exact value of the result to know how many decimals the result will have. Since I wrote a program, which approximates PI based on dart throws, the two integers a and b can have much bigger values than 39268112 and 5000000.</p>

<p>If I would use </p>

<pre><code>cout &lt;&lt; setprecision(some number) &lt;&lt; (double)a / (double)b * 4;
</code></pre>

<p>I need to know the exact result first, before I can even enter the argument in setprecision()</p>

<p>My edited question would be if there is a way to automaticly put an argument in setprecision() so that it can display the exact result, without having to calculate it myself first.</p>