Autor Beitrag
Unzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 57



BeitragVerfasst: So 26.01.03 13:22 
Hallo Leute,

ich hab mal ne wichtige Frage: Ich habe mein Programm geschrieben und eine Variable als integer definiert. Ich weiß, dass bei der Division, die ich dann durchführen möchte, ein intger rauskommt. Wie kann ich Delphi überzeugen, dass eine Division auch bei integer-Variablen geht?
Alibi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 458

Win2K SP3
Delphi 6 Ent
BeitragVerfasst: So 26.01.03 13:46 
Ergebnis := Integer1 div Integer2;
Dargor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 59

Win2k SP4, WinXP Pro SP1
D6 Pers
BeitragVerfasst: Mo 27.01.03 11:33 
Oder:
Ergebnis:=trunc(Int1 / Int2);
overmoon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 16



BeitragVerfasst: Mi 05.02.03 16:08 
Ich habe noch einen weiteren Vorschlag.. :D

ausblenden Quelltext
1:
Ergebnis := round(Int1/Int2);					


Denn trunc schneidet einfach den Ganzzahlwert ab, während round (wie es der Name schon sagt... *g*) das Ergebnis rundet!

Könnte durchaus mal Vorteilhaft sein (Wenn man nicht weiß, ob das Ergebnis wieder eine Ganzzahl ergibt...)
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Mi 05.02.03 19:58 
Dargor hat folgendes geschrieben:
Oder:
Ergebnis:=trunc(Int1 / Int2);

Für eine reine Integer Division ist das dann doch ein wenig viel Aufwand. Warum erst Int1 und Int2 in eine Fließkommazahl umwandeln, dann dividieren und wieder in einen Integer zurück wandeln.

_________________
Ist Zeit wirklich Geld?