title: Converting KB to MB, GB, TB dynamically
body: <pre><code>public String size(int size){
      String hrSize = "";
      int k = size;
      double m = size/1024;
      double g = size/1048576;
      double t = size/1073741824;
  
      DecimalFormat dec = new DecimalFormat("0.00");
  
      if (k&gt;0)
      {
  
          hrSize = dec.format(k).concat("KB");
  
      }
      if (m&gt;0)
      {
  
          hrSize = dec.format(m).concat("MB");
      }
      if (g&gt;0)
      {
  
          hrSize = dec.format(g).concat("GB");
      }
      if (t&gt;0)
      {
  
          hrSize = dec.format(t).concat("TB");
      }
  
      return hrSize;
      }
  </code></pre>
  
  <p>This is a method that should return size in GB,MB, KB or TB. Input value is in KB.
  for example result for 1245 should be like 1.21MB but what I get is 1.00MB.</p>