title: Converting bytes to kilobytes/megabytes
body: <p>I have an attachments table that stores the size of the document in Bytes.</p>
  
  <p>I'm needing to display a result set of all documents in either KB or MB. In KB if the document is less than 1MB or in MB if the document is larger than 1MB.</p>
  
  <p>At the moment I have this within my query, but I'm struggling to get the display properly formatted in terms of rounding.</p>
  
  <pre><code>    CASE WHEN D.DocumentSize &lt; 1000000 THEN
          CONCAT(D.DocumentSize / 1024, 'KB')
      ELSE
          CONCAT(D.DocumentSize / 1048576, 'MB')
      END AS DocumentSizeText,
  </code></pre>
  
  <p>Here are some example values:</p>
  
  <pre><code>87336
  1458250
  346
  8434
  8434
  </code></pre>
  
  <p>346 bytes is going to display 0KB also, so ideally displaying 1KB would be ideal as a minimum. </p>