Autor Beitrag
The...
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122



BeitragVerfasst: So 10.07.05 02:18 
hi,
also folgendes: Ich habe ein label, im den ne zahl steht die aber bei jedem start des programmes anders ist (sone art test). nun diese zahl ist in etwas sooo,oooooooooooooooooo lang! Ich wollte sie aber runden auf so 2 stellen hintern ',' hat !

ausblenden Delphi-Quelltext
1:
label1.caption:=FloatToStr (round( ???? ));					



was muss beim '?' rein, also man könnte ja

ausblenden Delphi-Quelltext
1:
a: 2587116;					


machen, aber die zahl hinter 'a' ist ja schon wie gesagt immer anders und deswegen kann ich das so nicht machen.

danke schon mal.... :lol:

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Mo 11.07.2005 um 00:27
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 10.07.05 02:49 

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
ScorpionKing
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1150

Win XP

BeitragVerfasst: So 10.07.05 06:52 
ausblenden Delphi-Quelltext
1:
round()					


Könnte man sich fast denken, oder? :wink:

_________________
Aus dem Urlaub zurück!
Diabele$
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 53



BeitragVerfasst: So 10.07.05 08:20 
Er will ja noch 2 Nachkommastellen haben.
Ich bin mir nicht sicher, aber könnte man nicht zuerst die Zahl mit 100 Multiplizieren, dann round einsetzen und letztenendes wieder mit 100 dividieren?

Also in etwa so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function RundenMit2StellenHintermKomma(Kommazahl: Double): Double;
begin
  result := (round(Kommazahl * 100)) / 100;
end;
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: So 10.07.05 08:26 
Wenn du zwei Stellen hinter dem Komma haben möchtest, dann benutzt du am besten
ausblenden Delphi-Quelltext
1:
RoundTo(aZahl, -2);					

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: So 10.07.05 09:35 
Oder mache es so hier:

ausblenden Delphi-Quelltext
1:
2:
a:=5,62545132544;
Form1.Label1.Caption:=Format('%.2f', [a]);
pRoTeUs
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Windows XP prof
Delphi 2005 prof
BeitragVerfasst: So 10.07.05 09:36 
Wenn du RoundTo benutzt musst du dann aber noch die "Math" oben einbinden soweit ich weiß.
The... Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122



BeitragVerfasst: So 10.07.05 23:14 
hi,
also ich dachte mir das jetzt so,

ausblenden Delphi-Quelltext
1:
2:
a:=(label6.caption);
Label6.Caption:=Format('%.2f', [a]);


aber das geht nicht.... warum?

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 10.07.05 23:47 
Hallo,
du musst die Zeichenkette erst in eine Zahl umwandeln. Da es sich dabei um einen Float handelt, würde ich mal auf StrToFloat tippen. Falls ich mich jetzt irre - die Delphihilfe weiss weiter ;)

ausblenden Delphi-Quelltext
1:
2:
a:=StrToFloat(label6.caption);  
Label6.Caption:=Format('%.2f', [a]);


Gruß,
maxk

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
The... Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 122



BeitragVerfasst: Mo 11.07.05 02:54 
oh sehr gut, das ist super... so gehts auch :D

danke an alle, echt nett von euch !