将文件大小数值转换成B、KB、MB、GB


//delphi 将文件大小数值转换成B/KB/MB/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;

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM