title: Adjusting for precision when casting a uint64_t to a double
body: <p>I have a method that returns a string representation of time in the following format:  _HH:MM:SS.sss the method takes an uint64_t time in microseconds as an arg. I can divide the hours and minutes out easily enough, but when it comes to the seconds, I need to cast to a double so I can get the fraction of seconds as well.</p>
  
  <p>sample code:</p>
  
  <pre><code>std::string getDurationTime(uint64_t time){
  
    std::string returnTime="";
  
     uint64_t tempTime = time;
     uint64_t hours = (tempTime / 3600000000);
     tempTime -= (hours * 3600000000);
  
     uint64_t minutes = (tempTime / 60000000);
     tempTime -= (minutes * 60000000);
  
     double seconds = (double(tempTime) / 1000000);
  
     stringstream timeOut;
  
     timeOut&lt;&lt;std::setw(2)&lt;&lt;std::setfill('0')&lt;&lt;hours&lt;&lt;":"&lt;&lt;std::setw(2)&lt;&lt;std::setfill('0')&lt;&lt;minutes&lt;&lt;":"&lt;&lt;std::fixed&lt;&lt;std::setw(6)&lt;&lt;std::setprecision(3)&lt;&lt;std::setfill('0')&lt;&lt;seconds;
  
    returnTime = "_" + timeOut.str();
  
    return returnTime;
  
  }
  </code></pre>
  
  <p>So  a number like 103566 should return a value of _00:00:00:104, but instead it is returning _00:00:00:103. When I put a break point on seconds, the value is 0.103499999.  Is there a standard technique for adjusting for this precision? If I add .000001 to the resulting seconds will it fix the problem every time for that precision?</p>
  
  <p>any advice appreciated.</p>