title: Loss of Precision when Converting Double to String in C++
body: <p>So I know <code>setprecision(int n)</code> should be used when printing a double value with precision <code>n</code>. However, I've run into a problem on a project that I'm working on that is akin to this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main() {
      double var = 1.0000001;
      cout &lt;&lt; setprecision(10)&lt;&lt; var &lt;&lt; endl;
      string str = to_string(var);
      cout &lt;&lt; str &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>Here is the output:</p>
  
  <pre><code>1.0000001
  1.000000
  </code></pre>
  
  <p>In the project I'm working on, I need to save the double value as a string, and it will occasionally need more than six decimal places of precision. Here, precision is clearly lost in the conversion. Any pointers would be greatly appreciated.</p>