Autor Beitrag
supersass1
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Di 19.08.08 13:37 
Hallo,

ich möchte eine Zahl enzeigen, die grundsätzlich aus 4 Zeichen besteht.
Demnach ist folgendes erlaubt, und muss erlaubt sein: 0001, 0002, ...

Doch wie programmiert man dies?
Ich habe eben schon versucht, etwasm it einer for-Schleife hinzukriegen, aber erfolglos.

gibt es einen Befehl, der eine Zahl immer auf 4 Zeichen anzeigt?

viele liebe Grüße
supersass1 :)
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Di 19.08.08 13:40 
Du musst die Länge des Strings in einer while-Schleife prüfen und Nullen voran stellen.

ausblenden Delphi-Quelltext
1:
2:
while (Length (s) < 4) do
  s := '0' + s;


Wenn es einzig zur Anzeige sein soll, dann evtl. mal den Format-Befehl unter die Lupe nehmen.
supersass1 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 55



BeitragVerfasst: Di 19.08.08 13:43 
alles klar, denke dir :)
K.S.M.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 82

Windows 7 Professional
Delphi 2010, HTML, JavaScript, CSS, PHP, ein wenig C, Flash ActionScript 2.0/3.0, SQL, Assembler
BeitragVerfasst: Di 19.08.08 13:47 
Wenn du nur gerade Zahlen verwendest kannst du auch
ausblenden Delphi-Quelltext
1:
Result := Format('%.4d', [Zahl]);					

verwednen, wobei die 4 angibt wie viele Stellen es insgesamt sein sollen.

_________________
"Programmieren ist keine Kunst. Programmieren ist eine Fähigkeit!"
baka0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 489
Erhaltene Danke: 14

Win 10, Win 8, Debian GNU/Linux
Delphi 10.1 Berlin, Java, C#
BeitragVerfasst: Di 19.08.08 15:55 
Alternativ auch:
ausblenden Delphi-Quelltext
1:
FormatFloat('0000', DeineZahl);					

Heißt zwar FormatFloat, funktioniert aber auch mit ganzzahligen Werten (Integer).