如:
  223B->223B
  1536B->1.5KB
  1082132786053B->1,032,002.25MB(4舍5入)

解决方案 »

  1.   

    上了GB的话,也可以是1.23GB的形式,但一定要4舍5入保留2位小数。
    3x...
      

  2.   

    大致的写法if x > (2 shl 30) then begin
      s:= format('%nG', [x / (2 shl 30)]);
    end
    else begin
      if x > (2 shl 20) then begin
        s:= format('%nM', [x / (2 shl 20)]);
      end
      else begin
        if x > (2 shl 10) then begin
          s:= format('%nK', [x / (2 shl 10)]);
        end
        else
          s:= format('%dB', [x]);
      end;
    end
      

  3.   

    发现 CoolSlob 的熊迹,
    我要去报告
      

  4.   

    function BytesToStr(const i64Size: Int64): string; 
    const 
      i64GB = 1024 * 1024 * 1024; 
      i64MB = 1024 * 1024; 
      i64KB = 1024; 
    begin 
      if i64Size div i64GB > 0 then 
        Result := Format('%.2f GB', [i64Size / i64GB]) 
      else if i64Size div i64MB > 0 then 
        Result := Format('%.2f MB', [i64Size / i64MB]) 
      else if i64Size div i64KB > 0 then 
        Result := Format('%.2f KB', [i64Size / i64KB]) 
      else 
        Result := IntToStr(i64Size) + ' Byte(s)'; 
    end;