Hàm tính giá trị Byte, MB, GB trong Delphi


Hàm này trả về giá trị MB, GB từ một giá trị Byte
function FormatByteSize(const bytes: Integer): 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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s