title: Python - rounding to the nearest integer
body: <p>I've been trying to figure this out for ages but with no luck. I need to round each coefficient to the nearest integer. </p>
  
  <p>To do this I introduce a small number dq=0.0001. If a[0]=0.5, then round(a[0]) = 0.0; this is clearly not good. However, to work around this introduce dq: round(a[0]+dq) = round(0.5001) = 1.0; this is good.</p>
  
  <p>For negatives such as a[2] = -0.5: round(a[2]-dq) = round(-0.5001) = -1.0. I take into account the negatives using if statements. This is my code which does not return the right value:</p>
  
  <pre><code>a= 0.5,0.5,-0.5,-0.5
  dq = 0.0001 #small number
  
  b = round(a[0]+dq), round(a[1]+dq), round(a[2]+dq), round(a[3]+dq)
  
  if a[0] &lt; 0:
      b[0] == round(a[0]-dq)
  if a[1] &lt; 0:
      b[1] == round(a[1]-dq)
  if a[2] &lt; 0:
      b[2] == round(a[2]-dq)
  if a[3] &lt; 0:
      b[3] == round(a[3]-dq)
  
  print(b)
  </code></pre>
  
  <p>Output: </p>
  
  <pre><code>(1,1,0,0)
  </code></pre>
  
  <p>Clearly it is the if statements that are dysfunctional.</p>
  
  <p>P.s. and I need to be able to use the resulting b in later calculations.</p>