title: How to effectively convert double to int in c++?
body: <p>Sorry for not being specific, I just thought the context isn't important.</p>
  
  <p>Anyway the question can be seen as an extension of my other question on <a href="https://stackoverflow.com/questions/14000715/progressbar-range-and-position-how-to-handle-big-numbers-in-c">Progressbars in win32</a> should I put the whole code here or the link is enough ?</p>
  
  <p>The problem in its simplest form can be described as :</p>
  
  <pre><code>double d1 = x.xxxxxx;
  double d2 = x.xxxxxx;
  double d3 = x.xxxxxx;
  double d4 = x.xxxxxx;
  double d5 = x.xxxxxx;
  ...
  ...
  double dn = x.xxxxxx;
  
  
  int i1 = (int)d1;
  int i2 = (int)d2;
  int i3 = (int)d3;
  int i4 = (int)d4;
  int i5 = (int)d5;
  ...
  ...
  int in = (int)dn;
  
  int i = i1+i2+i3+i4+i5+...+in;
  double d = d1+d2+d3+d4+d5+...+in;
  
  now i needs to be not less then d - 0.5;
  </code></pre>
  
  <p>How to do that ?</p>
  
  <p>EDIT : Code modified.
  EDIT 2 : The number of n can not be predicted, and it is possible that d1,d2,...,dn are less then 1, something like, 0.345627.</p>