[译]把字节数显示成kb或gb的函数

  • 主题发起人 SUNSTONE的Delphi笔记
  • 开始时间
S

SUNSTONE的Delphi笔记

Unregistered / Unconfirmed
GUEST, unregistred user!
经常用到把字节数显示成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;

作者:sunstone 发表于 2010/12/22 13:31:00 原文链接 //blog.csdn.net/sunstone/article/details/6091520
阅读:1479

查看更多...
 

Similar threads

S
回复
0
查看
613
SUNSTONE的Delphi笔记
S
S
回复
0
查看
626
SUNSTONE的Delphi笔记
S
S
回复
0
查看
927
SUNSTONE的Delphi笔记
S
S
回复
0
查看
752
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
顶部