title: Python format size application (converting B to KB, MB, GB, TB)
body: <p>I am trying to write an application to convert bytes to kb to mb to gb to tb.
  Here's what I have so far:</p>
  
  <pre><code>def size_format(b):
      if b &lt; 1000:
                return '%i' % b + 'B'
      elif 1000 &lt;= b &lt; 1000000:
          return '%.1f' % float(b/1000) + 'KB'
      elif 1000000 &lt;= b &lt; 1000000000:
          return '%.1f' % float(b/1000000) + 'MB'
      elif 1000000000 &lt;= b &lt; 1000000000000:
          return '%.1f' % float(b/1000000000) + 'GB'
      elif 1000000000000 &lt;= b:
          return '%.1f' % float(b/1000000000000) + 'TB'
  </code></pre>
  
  <p>The problem is, when I try the application I get everything after the decimal zeroing out.
  example
  <code>size_format(623)</code> yields
  '623B'
  but with <code>size_format(6200)</code>,
  instead of getting '6.2kb'
  I'm getting '6.0kb'.
  Any ideas why?</p>