std::cout << Predicting the automatic field width in displayed for an arbitrary double
<p>I'm displaying a large number of doubles on the console, and I would like to know in advance how many decimal places std::cout will decide to display for a given double. This is basically so I can make it look pretty in the console.
e.g. (pseudo-code)</p>

<pre><code>feild_width = find_maximum_display_precision_that_cout_will_use( whole_set_of_doubles );
...
// Every cout statement:
std::cout &lt;&lt; std::setw( feild_width ) &lt;&lt; double_from_the_set &lt;&lt; std::endl;
</code></pre>

<p>I figure cout "guesses"? a good precision to display based on the double. For example, it seems to display</p>

<pre><code>std::cout &lt;&lt; sqrt(2) &lt;&lt; std::endl;
</code></pre>

<p>as 1.41421, but also</p>

<pre><code>std::cout &lt;&lt; (sqrt(0.5)*sqrt(0.5) + sqrt(1.5)*sqrt(1.5)) &lt;&lt; std::endl;
</code></pre>

<p>as 2 (rather than 2.000000000000?????? or 1.99999999?????). Well, maybe this calculates to exactly 2.0, but I don't think that <code>sqrt(2)</code> will calculate to exactly 1.41421, so std::cout has to make some decision about how many decimal places to display at some point, right?</p>

<p>Anyway possible to predict this to formulate a <code>find_maximum_display_precision...()</code> function?</p>
