Autor Beitrag
Halunkel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: So 07.05.06 03:35 
Hallo!
Ich bräuchte mal wieder eure Hilfe!!

Wie schaffe ich es nur den 1000er Wert einer Zahl bei der Berechnung zu verwenden?

Also was ich damit meine ist folgendes: Man gibt in einem Editfeld eine Punktzahl ein und nun sollen in anderen Feldern Werte ausgegeben werden, entsprechend der Punktzahl!

Z.B. Punktzahl 2000
Ausgabe: 2
Punktzahl: 4257
Ausgabe: 4
Punktzahl: 8982
Ausgabe: 8

Danke!!
LLCoolDave
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 212

Win XP
Delphi 2005
BeitragVerfasst: So 07.05.06 08:16 
In solchen Fällen sind div und mod genau das richtige. mod gibt den Rest einer Division, div nur das ganzzhlige Ergebnis zurück.

2345 div 1000 = 2, da 1000 2 mal in 2345 geht
4673 div 1000 = 4, da 1000 4 mal in 4673 geht

5234 mod 1000 = 234, da 5234/1000 = 5 Rest 234 ist.
Halunkel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: So 07.05.06 21:58 
Welcher Variablentyp sollte die Variable denn haben, damit div bzw. mod funktionieren??

Ich habe folgendes ausprobiert, das klappt aber leider nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var zahl1, ergebnis : double;

begin
 zahl1 := StrToFloat (Edit1.Text); 

 ergebnis := zahl1 div 1000;{hier zeigt er mir dann einen Fehler an!!}

 Edit3.Text := FloatToStr (ergebnis);
end;


Leider klappts auch nicht mit integer!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 07.05.06 22:06 
Delphi unterscheided zwischen Integer (div) und Gleitkomma (/) bei der Division ...

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 07.05.06 22:06 
Wie wärs mit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var zahl1: double; 
ergebnis : Integer;

begin
 zahl1 := StrToFloat (Edit1.Text); 

 ergebnis := zahl1 div 1000

 Edit3.Text := IntToStr (ergebnis);
end;

_________________
Markus Kinzler.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 07.05.06 22:10 
user profile iconmkinzler hat folgendes geschrieben:
Wie wärs mit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var zahl1: double; 
ergebnis : Integer;

begin
 zahl1 := StrToFloat (Edit1.Text); 

 ergebnis := zahl1 div 1000

 Edit3.Text := IntToStr (ergebnis);
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
var zahl1: double; 
ergebnis : Integer;

begin
 zahl1 := StrToFloat (Edit1.Text); 

 ergebnis := trunc(zahl1) div 1000;

 Edit3.Text := IntToStr (ergebnis);
end;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Halunkel Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: So 07.05.06 22:37 
Mit "trunc" hats funktioniert!! :-)

Was genau bewirkt trunc??

also muss ich wenn ich div und mod benutze immer trunc vor die variable schreiben??
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 07.05.06 23:33 
Trunc bewirkt ein Abrunden der Zahl und gibt einen Integer zurück. Schau diesbezüglich einfach mal in der DOH unter Trunc, Div und Mod nach, da sollte einiges zur Erklärung zu finden sein ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.