Function format file size (Work with delphi)

function FormatByteSize(const bytes: LongInt): string;
const B = 1; // byte
  KB = 1024 * B; // kilobyte
  MB = 1024 * KB; // megabyte
  GB = 1024 * MB; // gigabyte
begin
  if bytes > GB then result := FormatFloat('#.## GB', bytes / GB)
  else if bytes > MB then result := FormatFloat('#.## MB', bytes / MB)
  else if bytes > KB then result := FormatFloat('#.## KB', bytes / KB)
  else result := FormatFloat('#.## bytes', bytes);
end;

Comments