// Return a formatted string from bytes
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;
No comments:
Post a Comment