Autor Beitrag
OlliWausD
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 212

Win 2000/XP
Delphi 5 Professional - Interbase/Firebird
BeitragVerfasst: Do 03.03.05 12:09 
hi Leutz,

ich bräuchte mal kurz nen kleinen Denkanstoß!

Folgendes Problem:

ich habe x, y und das Ergebnis

Beispiel:

x: 200
y: 10
Ergebnis: = x/y --> 20

Ich übergebe nun die Zahl 20 ohne Nachkommastelle

Wenn ich allerdings

x: 208
y: 24
Ergebnis: --> 8,66666666666666666666666

In diesem Fall müsste ich auf 1 Nachkommastelle mein Ergebnis ausgeben.

Ich muss quasi feststellen, ob das Ergebnis Nachkommastellen hat, und wenn ja, diese mit 1 Nachkommastelle ausgeben. Wie stell ich fest, ob das Ergebnis Nachkommastellen hat???

mfg

OlliW

_________________
Take it easy
HariboHunter
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 49

Win Xp pro
Delphi 7 pro
BeitragVerfasst: Do 03.03.05 12:16 
schau mal in der Delphi- hilfe unter 'div' und 'mod'.

und dann mit einer abfrage versuchen , if modulo > 0 then begin ....

_________________
Viel von Nix, ist auch nix!
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: Do 03.03.05 12:18 
Ich glaube, da solltest du mal ein bissel mit FloatToStrF rumspielen, und je nach Bedarf die Parameter ggf. ändern. Ob eine Zahl Nachkommastellen hat, kann man z.B. mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if abs(Zahl - round(Zahl)) = 0 then ...
//oder besser: 
if abs(Zahl - round(Zahl)) < eps then ...
// mit eps >0 (hihi, was sonst), aber sehr klein, z.B. 0.000000001;

_________________
We are, we were and will not be.
Amiga-Fan
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 534



BeitragVerfasst: Do 03.03.05 12:30 
sorry für den Einwurf aber könnte bitte jemand die Fehler in der Überschrift beheben? Ihr könnt anschließend diesen Post löschen.
OlliWausD Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 212

Win 2000/XP
Delphi 5 Professional - Interbase/Firebird
BeitragVerfasst: Do 03.03.05 13:14 
ahh, sorry Jungs,

war heut früh weng verplant.

habs schon:

z := (x mod y)

if z <> 0 then Ergebnis = formatfloat('0.0',(x/y))
else
Ergebnis = (x/y)

Trotzdem Danke, an alle die gepostet haben :P

mfg

OlliW

_________________
Take it easy