Autor Beitrag
ASBMorsi2003
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Di 15.04.03 14:52 
Ich habe eine real Variable und möchte diese jetzt auf 2 Stellen nach dem Komma gekürzt haben! Wie funzt das! Danke im voraus!!!
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 15.04.03 15:01 
Eigentlich ganz einfach...
ausblenden Quelltext
1:
2:
3:
4:
var
  x: Real;

x := Round(x * 100)/100;

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 15.04.03 15:02 
Versuchs mal mit
ausblenden Quelltext
1:
gerundet:=Trunc(variable * 100) / 100;					


gerundet muss natürlich auch ein Float-Typ sein.

Gruß
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Di 15.04.03 15:03 
Hmm, war jmd schneller. Jetzt ist nur die Frage, ob er sie gerundet oder gekürtzt haben will, so wie er oben geschrieben hat.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Di 15.04.03 15:08 
UGrohne hat folgendes geschrieben:
Hmm, war jmd schneller. Jetzt ist nur die Frage, ob er sie gerundet oder gekürtzt haben will, so wie er oben geschrieben hat.

Naja, jetzt hat er halt beide Varianten da... ;)

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
mlamers
Hält's aus hier
Beiträge: 11



BeitragVerfasst: Di 15.04.03 20:58 
Wenn es nur um die Darstellung, also die Umwandlung in einen String geht:
ausblenden Quelltext
1:
2:
3:
var t : Real;

String:=FormatFloat('0.00',t)


Gruß
Michael
O'rallY
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 563



BeitragVerfasst: Mi 16.04.03 10:41 
Ich glaube bei RoundTo kann man die Anzhal der Nachkommstellen als Parameter übergeben...

_________________
.oO'rallY
Linux is like a tipi: No gates, no windows and a gnu-eating apache inside...
NoEon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 138

win9x, win 2000, win xp, linux 8.0

BeitragVerfasst: Mi 16.04.03 14:26 
Hi willst Du die Variable augeben??

ausblenden Quelltext
1:
 label1.caption:=FloatToStrF(var, ffFixed, 18,2);					

damit gibst Du eine belibiege Zahl mit 2 NAchkomma Stellen aus... vielleicht hilft Dir das ja weiter!


Gruss

NoEoN
pappelinda
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mo 26.05.03 13:20 
Titel: round rundet wie ein banker
@Motzi wg. x := Round(x * 100)/100;

Liegt (x*100) genau in der Mitte zwischen zwei ganzen Zahlen, wird immer die gerade Zahl zurückgeliefert ("Banker’s Rounding").
D.h. 1,005 wird leider nicht auf 1,01 sondern auf 1,00 gerundet.
ErnestoChe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 528

Win 2000 pro, CRUX 2.0
Delphi 6 Pers, Open K3
BeitragVerfasst: Mo 26.05.03 13:45 
Hallo,

so gehts:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Button1Click(Sender: TObject);
var
  d: double;
  str: String;
begin
  d := StrToFloat(Edit1.Text);
  str := Format('%4.2f', [d]);
  Edit2.Text := str;
end;


MFG

- Ernesto -