Autor Beitrag
chriss1988
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 389

windows xp prof,home,windows98
delphi5
BeitragVerfasst: Mi 28.09.05 08:41 
wie kann ich es so machen, das ich zb 2 stellen nach dem komma hab das heißt ich rechne zb 100/3 und er soll mir 33,33 nur anzeigen


mein erster gedanke war so

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
uses Math;
function RundeAufStelle(zahl: double; stellen: integer): double;var multi: double;

begin  
multi:=IntPower(10, stellen);  

zahl:=round(zahl*multi);  
result:=zahl/multi;
end;


Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
Moderiert von user profile iconraziel: Topic aus VCL (Visual Component Library) verschoben am Di 04.10.2005 um 09:35
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: Mi 28.09.05 09:03 
Falls du es nur zur Darstellung benötigst, nimmst du FloatToStr, oder FloatToStrF.
Wenn du es als gerundete Zahl benötigst, sieht deine Funktion auf den ersten Blick fast richtigt aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
uses Math;
function RundeAufStelle(zahl: extended; stellen: integer): extended
var
  multi : LongInt;
begin
  multi:=IntPower(10, stellen);
  zahl:=round(zahl*multi);
  result:=zahl/multi;
end;

(ungetestet!)
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: Mi 28.09.05 09:42 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var n: real;
begin
  n:= 100/3;
  showmessage(format('Ergebnis: %.2f', [n]));
  // bzw.
  LabelX.Caption := format('Ergebnis: %.2f', [n]);
end;


Wenn es nur um eine Ausgabe geht kannst du ja auch format verwenden.