title: C++ chrono: Get seconds with a precision of 3 decimal places
body: <p>This might sound like a basic question but I've searched a lot. I am trying to <strong>time-profile</strong> a function call in <code>C++</code> &amp; need to log the time in seconds up to <code>3 decimal places</code>. For example <code>2.304 seconds</code> or <code>.791 seconds</code>. I am trying to use <code>std::chrono</code> to do it like this:</p>
  
  <pre><code>auto start_time = std::chrono::system_clock::now();
  DoSomeOperation();
  std::chrono::duration&lt;double&gt; elapsed_time = std::chrono::system_clock::now() - start_time;
  double execution_time = elapsed_time.count();
  
  std::cout &lt;&lt; "execution_time = " &lt;&lt; execution_time &lt;&lt; std::endl;
  </code></pre>
  
  <p>Following is the output I am getting:</p>
  
  <pre><code>execution_time = 1.9e-05
  execution_time = 2.1e-05
  execution_time = 1.8e-05
  execution_time = 1.7e-05
  </code></pre>
  
  <p>I am sure that <code>DoSomeOperation</code> only takes a few <code>milliseconds</code> to complete &amp; I need the number in <code>seconds</code>. I need the number in double to use it in a different calculation.</p>
  
  <p><em>How can I convert this weird <code>1.9e-05</code> into a sensible number in <code>double</code> which yields in seconds like <code>.304</code> or <code>.067</code> ?</em></p>
  
  <p>Trying the code from <a href="https://stackoverflow.com/questions/14391327/how-to-get-duration-as-int-millis-and-float-seconds-from-chrono">here</a>, I've the same problem.</p>