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 如何判断html编码格式,解决乱码问题

Delphi tms web core webmemo 横竖滚动条

winapi 字符及字符串函数(11): lstrcpyn - 复制字符串, 同时指定要复制的长度

Delphi 串口控制继电器

Delphi 15位身份证号码转18位身份证号码

Delphi adoconnection1 事务

Delphi的idhttp报iohandler value is not valid错误的原因

Delphi 单击最小化按钮隐藏单击托盘显示

Delphi 获取 设置文件时间

Delphi从内存流中判断图片格式

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



打赏

取消

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

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

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

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

评论

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