將文件大小數值轉換成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