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 实现文件拖放完整代码

Delphi fdmemtable1内存表字段排序

Delphi showmainform := false 失效的解决办法

Delphi dbgrid适应宽度

Delphi firedac 下的 sqlite 创建数据库

Delphi实现tedit控件的外观只有一条下划线

Delphi的cpu调试窗口

Delphi system.messaging.pas例子

Delphi 大小写字符串转换

Delphi源码获取网络图片缓存的地址

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



打赏

取消

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

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

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

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

评论

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