函数:友好显示字节

function BytesFriendly(const Bytes : integer):string;
begin
  if Bytes < 1024 then
  begin
    Result := Format('%s', [IntToStr(Bytes)]) + 'B';
    Exit;
  end;
  if (Bytes >= 1024) and (Bytes < (1024 * 1024)) then
  begin
    Result :=  Format('%n', [Bytes / 1024]) + ' KB';
    Exit;
  end;
  if (Bytes >= (1024*1024)) and (Bytes < (1024 * 1024 * 1024)) then
  begin
    Result :=  Format('%n', [Bytes / (1024 * 1024)]) + ' MB';
    Exit;
  end;
  if Bytes >= (1024*1024*1024)  then
  begin
    Result :=  Format('%n', [Bytes / (1024 * 1024 * 1024)]) + ' GB';
    Exit;
  end;
end;
posted @ 2006-11-07 09:41  hingman  阅读(142)  评论(0)    收藏  举报