把字节数显示成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;

posted on 2011-06-17 22:38  jxgxy  阅读(328)  评论(0编辑  收藏  举报

导航