Einzelnen Beitrag anzeigen

Benutzerbild von Khabarakh
Khabarakh

Registriert seit: 18. Aug 2004
Ort: Brackenheim VS08 Pro
2.876 Beiträge
 

Re: Dateigröße formatieren?

  Alt 25. Nov 2005, 17:35
Zitat von igel457:
Mach eine Funktion FileSizeToStr:

Delphi-Quellcode:
function FileSizeToStr(size:int64):string;
begin
  if size < 1024 then result := inttostr(size)+'Byte';
  if (size > 1024) and (size < 1024*1024) then result := formatfloat('0.00',size/1024)+'KB';
  if (size > 1024*1024) and (size < 1024*1024*1024) then
   result := formatfloat('0.00',size/1024/1024)+'MB';
  if (size > 1024*1024*1024) then
   result := formatfloat('0.00',size/1024/1024/1024)+'GB';
end;
Hoffe das hilft...
Viel zu lang .
Delphi-Quellcode:
function FileSizeToStr(const ASize: Int64): string;
const
  Units: Array[0..8] of string = ('Byte', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
                                                                              // Ab hier wird es unwahrscheinlich ^^
var
  Index: Integer;
begin
  Assert(ASize >= 0);
  Index := Trunc(ln(ASize) / ln(2) / 10);
  Result := Format('%.2f %s', [ASize / (1 shl (Index * 10)), Units[Index]]);
end;
*scnr*
Sebastian
Moderator in der EE
  Mit Zitat antworten Zitat