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 使用 idhttp 获取 utf-8 编码的中文网页

Delphi程序将自身可执行文件拷贝到u盘的代码

Delphi 输出用空格对齐字符串的函数

Delphi xe5 实现获取本地的ip地址

Delphi string.split 按照任意字符串分割语句

Delphi 查找某函数在某个单元

Delphi tedit 编辑框 中文使用说明

Delphi 类的声明

Delphi cardpanel1 简单的切换

Delphi xe5做一个android网页框架

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



打赏

取消

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

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

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

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

评论

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