本文整理自网络,侵删。
经常用到把字节数显示成kb或gb,函数如下
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; // www.delphitop.com
相关阅读 >>
Delphi 使用 idhttp 获取 utf-8 编码的中文网页
Delphi string.split 按照任意字符串分割语句
更多相关阅读请进入《Delphi》频道 >>