Autor Beitrag
Paulchengb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Mo 05.03.07 16:51 
Hallo,
ich bin gerade dabei, ein kleines Rechenprogramm für Dart zu programmieren. Ich bin ein Delphi-Anfänger.
Es soll die Summe von 3 Würfen berechnet werden. Als Ergebnis soll zum Einen die Summer der 3 Würfe und zum Anderen die "Restaugenzahl" angezeigt werden, sprich
"301-die Summer der 3 Würfe"

Die Summe geht ohne Probleme, nur bei der Restaugenzahl kommt als Ergebnis immer so etwas raus: 2,6E2 oder 2,3E2. Damit kann ich eher weniger anfangen.
Hier mal der Code:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.Button1Click(Sender: TObject);
var w1,w2,w3,s,x,y,z,r,m: extended;
//wi=würfe
//x,y,z=single,double,triple pro wurf
//s=summe
//r=rest
//m=modus

begin

w1:=strtofloat(labelededit1.Text);
w2:=strtofloat(labelededit4.Text);
w3:=strtofloat(labelededit5.Text);
m:=strtofloat(labelededit6.Text);
x:=strtofloat (edit1.Text);
y:=strtofloat (edit2.Text);
z:=strtofloat (edit3.Text);
s:=x*w1+y*w2+z*w3;
r:=m-s;
labelededit2.Text:=floattostrf (s,fffixed,0,0);
labelededit3.Text:=floattostrf (r,fffixed,0,0);

end;


Waran könnte der Fehler liegen?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 05.03.07 16:56 
Nimm als Variablentyp statt "extended" mal "Integer".
Und statt StrToIFloat musst Du dann natürlich StrTInt verwenden.
Paulchengb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 39



BeitragVerfasst: Mo 05.03.07 17:00 
Danke. Geht super.

Gibt es auch eine Erklärung, warum dass mit extended nicht geht?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 05.03.07 17:04 
Extended ist vom Typ Fließkommazahl.
Leider rechnet der Computer nicht im Dezimalsystem, sondern im Dualsystem. Beim Umrechnen kann es dann zu Ungenauigkeiten kommen. Diese führen dann zu dem von Dir beschriebenen Problem.