Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two issues you have to consider. The first is the precision parameter, which defaults to 6 (but which you can set to whatever you like). The second is what this parameter means, and that depends on the format option you are using: if you are using fixed or scientific format, then it means the number of digits after the decimal (which in turn has a different effect on what is usually meant by precision in the two formats); if you are using the default precision, however (<code>ss.setf( std::ios_base::fmtflags(), std::ios_base::formatfield )</code>, it means the number of <strong>digits</strong> in the output, regardless of whether the output was actually formatted using scientific or fixed notation. This explains why your display is <code>12.1231</code>, for example; you're using both the default precision and the default formattting.</p> <p>You might want to try the following with different values (and maybe different precisions):</p> <pre><code>std::cout.setf( std::ios_base::fmtflags(), std::ios_base::floatfield ); std::cout &lt;&lt; "default: " &lt;&lt; value[i] &lt;&lt; std::endl; std::cout.setf( std::ios_base::fixed, std::ios_base::floatfield ); std::cout &lt;&lt; "fixed: " &lt;&lt; value[i] &lt;&lt; std::endl; std::cout.setf( std::ios_base::scientific, std::ios_base::floatfield ); std::cout &lt;&lt; "scientific: " &lt;&lt; value[i] &lt;&lt; std::endl; </code></pre> <p>Seeing the actual output will probably be clearer than any detailed description:</p> <pre><code>default: 0.1 fixed: 0.100000 scientific: 1.000000e-01 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload