Einzelnen Beitrag anzeigen

ByTheTime

Registriert seit: 24. Sep 2011
Ort: Frankfurt
297 Beiträge
 
Delphi XE2 Architect
 
#1

Byte --> Kb/Mb/Gb

  Alt 8. Aug 2013, 16:22
Hallo,
ich benutze folgende Routine um Byte(s) in eine für den Anwender schönere Darstellung umzuwandeln:

Delphi-Quellcode:
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;
Ich rechne die Dateigröße mehrerer Dateien zusammen und erhalte "143866884245" Byte. Das sind ~134GB. Allerdings erhalte ich mit der oben aufgeführten Routine 1,99GB.

Ich weiß nich was da schief geht.

Gruß,
Lukas
Lukas
  Mit Zitat antworten Zitat