Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Format funktion mit Int64 (https://www.delphipraxis.net/48163-format-funktion-mit-int64.html)

ErazerZ 21. Jun 2005 15:14


Format funktion mit Int64
 
hey,
also ich hab da ein problem mit Format( funktion, ich glaub es liegt an den langen zahlen (Int64), aber ich kann nicht die bytes von zb. 50GB festplatte formatieren, also ich würde es so haben wollen zB von 50237591552 zu 50.237.591.552
aber ich bekomm immer ein fehler
Zitat:

Format '%.n' invalid or incompatible with argument.
mein code um 50237591552 bytes um zu formatieren
Delphi-Quellcode:
var
  UsedB: Int64;
begin
..
frmMain.lblUsed.Caption := Format('%.n Bytes', [UsedB]);
das ganze funktioniert wenn ich mach [UsedB / 1000] - aber ich wills schon genauer haben
hoffentlich kann mir jemand helfen :)

cya

scp 21. Jun 2005 15:42

Re: Format funktion mit Int64
 
Ich glaub da hilft nur IntToStr(), da Format() meines Wissens nicht 64-bit-fähig ist. Auch die API-Funktion wvsprintf() scheint kein 64-bit zu können.
Delphi-Quellcode:
var
  UsedB: Int64;
begin
..
frmMain.lblUsed.Caption := IntToStr(UsedB) + ' Bytes';

ErazerZ 21. Jun 2005 15:51

Re: Format funktion mit Int64
 
ja so hatte ich es auch, jedoch ist das so unübersichtlich

marabu 21. Jun 2005 16:04

Re: Format funktion mit Int64
 
So schaut es netter aus:

Delphi-Quellcode:
function Format64(z: int64): string;
var
  i: integer;
  neg: boolean;
begin
  neg := z < 0;
  z := abs(z);
  Result := IntToStr(z);
  i := Length(Result) - 2;
  while i > 1 do begin
    Insert(ThousandSeparator, Result, i);
    Dec(i, 3);
  end;
  if neg then
    Result := '-' + Result;
end;
Grüße vom marabu

ErazerZ 21. Jun 2005 16:13

Re: Format funktion mit Int64
 
@marabu: danke sehr! aber ich hab auch ne ähnliche funktion geschrieben, deine is aber kleiner :)

cya


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz