Autor Beitrag
christoph
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP(SPack1),Win 2000(Spack3)
Delphi 6(Spack2)
BeitragVerfasst: Mo 10.03.03 12:22 
Hi allerseits gibt es eigentlich ne function um die Länge einer Zahl (Typ Integer) zuermitteln ??
Ich meien das so 1-9 =1
10 - 99 = 2

im Prinzip so wie man die Länge eines Strings ermittelt .(length)..

Vielen Dank für eure Bemühungen.....
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Mo 10.03.03 12:29 
LaengeDerZahl = Length(IntToStr(Zahl));
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 10.03.03 12:30 
Versuch's mal hiermit:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
VAR zahl : Integer;
    laenge : INTEGER;
begin
  laenge:=0;
  repeat
    inc(laenge);
    zahl := zahl div 10;
  until zahl = 0;
end;

Alternativ kannst Du die Zahl natürlich in einen String umwandeln und dann die Länge des Strings bestimmen, aber ich finde, das ist eine Verschwendung von Rechenzeit.

MfG,
Peter

<edit>
Mist, da war ja einer schneller!
</edit>

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 14.03.03 14:29 
ausblenden Quelltext
1:
2:
3:
var Laenge, Zahl: Integer;
begin
  Laenge := Ceil(Log10(Zahl));


Benötigt Unit Math! Keine Ahnung, wie das mit der Geschwindigkeit ist.

_________________
Life is a bad adventure, but the graphic is really good!