Autor Beitrag
Leathl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 15:34 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:03, insgesamt 1-mal bearbeitet
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 01.03.03 15:39 
Es gibt 2 Arten zu Teilen:

1. div = ganzahlige Division => 10 div 3 = 3
2. / = Division => 10 / 3 = 3,33333333333...

Jetzt kommt es auf den Typ der Ergebnisvariable an. Bei Ganzahl-Variablen (Integer, Cardinal, Byte) musst du div benutzen.
Bei Fließkomma-Variablen (real, single, double, extended) musst du / benutzen.

Beispiel:
ausblenden Quelltext
1:
2:
3:
a, b, c: Integer;
c := a div b //funktioniert einwandfrei
c := a / b //ergibt deinen Fehler

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.


Zuletzt bearbeitet von derDoc am Sa 01.03.03 16:04, insgesamt 2-mal bearbeitet
Leathl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 15:41 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:04, insgesamt 1-mal bearbeitet
Leathl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 15:58 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:05, insgesamt 1-mal bearbeitet
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 01.03.03 16:04 
Wenn du deine Variablen als reelle Zahlen deklariert hast, musst du / zum dividieren benutzen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Leathl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 16:10 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:05, insgesamt 1-mal bearbeitet
Leathl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 16:21 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:06, insgesamt 1-mal bearbeitet
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 01.03.03 16:32 
Ich rechne dir das mal vor:
Zitat:
a div Gold

60 div 21 = 2
da 60 / 21 = 2,857142 und div alles hinter dem Komma abschneidet

Zitat:
a div Gold * Goldbb

60 div 21 = 2 * 400 = 800
alles immer schön der Reihe nach

Zitat:
a div Gold * Goldbb div a

60 div 21 = 2 * 400 = 800 div 60 = 13
da 800 / 60 = 13,33333 und wie gesagt div die Nachkommastellen abschneidet.

Eine Möglichkeit wäre
ausblenden Quelltext
1:
(a div Gold) * (Goldbb div a)					

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 01.03.03 16:39 
Hier sind die zwei Möglichkeiten für die gleiche Rechnung:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  Gold, Goldbb, Goldd, a: Integer;
begin
  Gold := 21;
  Goldbb := 400;
  a := 60;
  Goldd := a div Gold * Goldbb div a;
  //Das Ergebniss ist 13
end;


Und nun für reelle Zahlen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var
  Gold, Goldbb, Goldd, a: Real;
begin
  Gold := 21;
  Goldbb := 400;
  a := 60;
  Goldd := a / Gold * Goldbb / a;
  //Das Ergebniss ist 19,04761905
end;


Hier siehst du den Unterschied zwischen div und /.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Leathl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 16:39 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:07, insgesamt 1-mal bearbeitet
Leathl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 276



BeitragVerfasst: Sa 01.03.03 16:45 
---


Zuletzt bearbeitet von Leathl am So 16.08.09 12:07, insgesamt 2-mal bearbeitet
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Sa 01.03.03 16:45 
@Leathl

Bist du dir im klaren was du rechnest? Oder tippst du die ganze Zeit nur herum?

Entweder reche ich mit Integer, dann weiß ich, daß die Werte gekürzt werden. Oder ich rechner Real und schneide zum Schluß die Nachkommastellen ab.

Guck dir noch mal ganz dringend an was Integerzahlen sind.

Tip:

ausblenden Quelltext
1:
x := Trunc( (a / Gold) * (Goldbb / a) );					


Ergebnis ist dann 19.


Zuletzt bearbeitet von Popov am Sa 01.03.03 16:47, insgesamt 1-mal bearbeitet
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Sa 01.03.03 16:47 
Wie schon beschrieben benutze Variablen der Typen Single, Double, Real oder Extended und als Operator /. Dann hast du das genaue Ergebniss deiner Rechnung.
Wenn du umbedingt ein glattes Ergebniss haben musst, dann benutze die Möglichkeit, die dir Popov beschrieben hat.
Und zu deinem String, wenn du ein Integer Ergebniss hast, dann machst du das mit IntToStr zu einem String, oder wenn du ein Real Ergebniss hast, dann geht das mit FloatToStr.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.