title: Truncate and round all elements of a list to 8 characters
body: <p>I need to truncate / round / justify all the elements of a list to 8 characters. The input list can contain int (that are never too long), str (that I can truncate) and floats as <code>float</code> <code>float64</code> or <code>str</code>.</p>
  <p>Below is a sample of my code :</p>
  <pre class="lang-py prettyprint-override"><code>data = [12452, &quot;too much characters&quot;, 0.12457544512, -0.12457544512, &quot;-1245154.8&quot;]
  processedData = []
  
  for d in data:
      processedValue = str(d)
      if len(processedValue) &gt; 8 and '.' in processedValue:
          decIndex = processedValue.index(&quot;.&quot;)
          processedValue = str(round(float(processedValue), 8 - (decIndex + 1)))
      elif len(processedValue) &gt; 8:
          processedValue = processedValue[:8]
  
      processedData.append(processedValue.rjust(8, &quot; &quot;))
  
  print(processedData)
  </code></pre>
  <p>The output and desired output :</p>
  <pre class="lang-py prettyprint-override"><code>['   12452', 'too much', '0.124575', '-0.12458', '-1245150.0'] # Output
  ['   12452', 'too much', '0.124575', '-0.12458', '-1245155'] # Desired Output
  </code></pre>
  <p>When the decimal is near the end of the 8 characters, my values are not rounded at the correct index. When I replace the <code>elif</code> condition by <code>if</code>, the length is correct but the last digit is still wrong. I've tried some other changes ending up in introducing errors for the other values.</p>