Autor Beitrag
delphinia
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131

XP Pro Sp2
Delphi 5 Standard
BeitragVerfasst: Mi 22.03.06 17:21 
Wie kann ich von 1 bis 100 zählen mit fürenden Nullen ergo

001
002
003

oder

010
011
012


danke Euch....
Ferrari
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 30

Win XP
Delphi 6 Personal
BeitragVerfasst: Mi 22.03.06 17:29 
Willst du die Zahl als String in einem Edit oder so ausgeben?

_________________
Mehr als ein Hesse kann der Mensch kaum werden.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mi 22.03.06 17:30 
such mal nach formatfloat();
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Mi 22.03.06 17:49 
Format-Funktion!

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
delphinia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131

XP Pro Sp2
Delphi 5 Standard
BeitragVerfasst: Mi 22.03.06 17:55 
beides hab ich ausprobiert aber irgendwie komme ich damit nicht zu recht ;(

Also mit format hab ich es hinbekommen nur ist beim umwandel wieder in einen Interger a la StrToInt die Nullen wieder weg ;(

tba := Format('00%.2d', [sp]);
Ferrari
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 30

Win XP
Delphi 6 Personal
BeitragVerfasst: Mi 22.03.06 18:00 
Wenn du die Nullen bei einem Integer haben willst, dann geht das nicht. Das geht nur bei einem String.

_________________
Mehr als ein Hesse kann der Mensch kaum werden.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mi 22.03.06 18:03 
...denn 1 ist eine Zahl, aber nicht '001'. 001 ist eine Darstellung einer Zahl. Für solche Zicken wie Computer ist das wichtig, für uns nicht.

Aber es kann Dir auch egal sein, denn Du kannst mit Zahlen wunderbar rechnen, und wenn du sie dann darstellenwillst, dann eben mit führenden Nullen, Blümchen oder bunt.

_________________
Na denn, dann. Bis dann, denn.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 22.03.06 18:03 
Da ein Integer intern sowieso als Folgen von Nullen und Einsen vorliegt, macht es keinen Sinn darüber nachzudenken, wie sich die Zahl in der Integer-Variable intern im Dezimalsystem darstellen würde.

_________________
We are, we were and will not be.
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Mi 22.03.06 18:18 
%03d schonmal als Formatstring versucht!?

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 22.03.06 20:19 
Hallo,

die Nullen in den hier geposteten Formatstrings sind überflüssig
'00%.2d' >> die Nullen werden vor den String gesetzt
Format('00%.2d',[1]) --> 0001
Format('00%.2d',[11]) --> 0011
Format('00%.2d',[111]) --> 00111
Format('00%.2d',[1111]) --> 001111

'%03d' >> Die Null wird nicht berücksichtigt,
der Wert 3 wird als Breitenangabe(with) gewertet, deshalb die führenden Leerzeichen:
Format('%03d',[1]) --> __1 (die Unterstriche sollen Leerzeichen andeuten)
Format('%03d',[11]) --> _11
Format('%03d',[111]) --> 111
Format('%03d',[1111]) --> 1111

Der Ansatz mit dem Punkt im Formatstring ist soweit richtig,
denn er dient als Trenner der Argumente Breitenangabe(with) und der Genauigkeitsangabe: ["." prec]
Format('%.5d',[1]) --> 00001
Format('%.5d',[11]) --> 00011
Format('%.5d',[111]) --> 00111
Format('%.5d',[1111]) --> 01111

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
delphinia Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 131

XP Pro Sp2
Delphi 5 Standard
BeitragVerfasst: Mi 22.03.06 20:21 
@Lannes :zustimm: ich danke Dir