delphi 把字节数显示成kb或gb的函数


本文整理自网络,侵删。

 

经常用到把字节数显示成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读写utf-8、unicode格式文本文件

Delphi 获取image.picture.data的数据

Delphi通过setupapi.dll列举和停用硬件设备

Delphi memo1删除前n行

Delphi 颜色表

Delphi 字符串与日期格式互转

Delphi 中string字符串转换byte[]字节数组

Delphi 实现窗体随着鼠标移动

Delphi package

Delphi 获取文件修改时间

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...