avoid rounding error (floating specifically) c++
<p><a href="http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/" rel="nofollow">http://www.learncpp.com/cpp-tutorial/25-floating-point-numbers/</a>
I have been about this lately to review C++.</p>

<p>In general computing class professors tend not to cover these small things, although we knew what rounding errors meant. </p>

<p>Can someone please help me with how to avoid rounding error?</p>

<p>The tutorial shows a sample code</p>

<pre><code>#include &lt;iomanip&gt;
int main()
{
    using namespace std;
    cout &lt;&lt; setprecision(17);
    double dValue = 0.1;
    cout &lt;&lt; dValue &lt;&lt; endl;
}
</code></pre>

<p>This outputs</p>

<blockquote>
  <p>0.10000000000000001</p>
</blockquote>

<p>By default float is kept 6-digits of precisions. Therefore, when we override the default, and asks for more (n this case, 17!!), we may encounter truncation (as explained by the tutorial as well). 
For double, the highest is 16. </p>

<p>In general, how do good C++ programmers avoid rounding error? 
Do you guys always look at the binary representation of the number?</p>

<p>Thank you.</p>
