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

相关阅读 >>

建议大家使用fastmm

Delphi 内存分配 stralloc

Delphi 中的颜色常量及效果图

Delphi memo中禁止汉字

Delphi 如何在tmemo,tedit或trichedit中获得插入符的位置

Delphi tbutton.onclick 匿名函数用法

Delphi datasnap 的http 调用返回json

Delphi 清除windows 图标缓存源代码

Delphi 创建文件夹并打开

Delphi生成32位随机数

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



打赏

取消

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

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

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

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

评论

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