Autor Beitrag
Smartie
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 205



BeitragVerfasst: Mo 27.06.05 12:56 
Hallo.

Ich fürchte,d iese Frage ist eine absolute anfängerfrage die ic hgrade stelle, aber... wie runde ich Werte?

Ich habe nämlich ein paar Double-Werte, die eeewig lang sind. Naja, ich brauche diese aber alle auf drei Stellen nach dem Komma gerundet.

Gibt es ne Funktion die das kann?

Lieben Gruß und Danke

Smartie
Asgar
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

XP Home Edition
D5
BeitragVerfasst: Mo 27.06.05 13:11 
mit round(wert) kannst du wohl auf ganze zahlen runden, glaube aber nicht das es fürs runden auf 3 stellen ne funktion gibt
Holgerwa
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 325

WIN XP Pro, Vista Business
Delphi 7 Pro, BDS 2006 Pro
BeitragVerfasst: Mo 27.06.05 13:11 
Hallo,

keine spezielle Funktion, aber so gehts:
ausblenden Delphi-Quelltext
1:
a := Round (zahl * 1000.0) / 1000.0;					

Holger
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Mo 27.06.05 13:21 
dabei ist jedoch anzumerken, dass borlands round funktion buggy ist!

[Edit1] falls du es nur zur ausgabe benötigst, schau dir mal die format strings an[/Edit1]
Smartie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 205



BeitragVerfasst: Mo 27.06.05 13:33 
user profile iconrochus hat folgendes geschrieben:
dabei ist jedoch anzumerken, dass borlands round funktion buggy ist!


Was heißt das?

Moderiert von user profile iconGausi: Quote-Tags repariert.
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Mo 27.06.05 13:50 
d.h. dass die Funktion "round" falsche Werte berechnet. Das Problem ist seit Ewigkeiten bekannt aber auch seit Ewigkeiten nicht von Borland gefixt. Ich find leider den Beitrag im BDN gerade nicht, sonst hätt ich ihn gepostet.

Gruß
Nicolai


[Edit1]: Here it is: qc.borland.com/wc/qcmain.aspx?d=8070 Bin jetzt aber nicht sicher, ob es sich auch auf Round ausgewirkt hat. Wir mussten jedenfalls die Standardfunktionen ersetzen.[/Edit1


Zuletzt bearbeitet von rochus am Mo 27.06.05 13:57, insgesamt 1-mal bearbeitet
Smartie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 205



BeitragVerfasst: Mo 27.06.05 13:56 
Ähm, was heißt konkret falsche Werte? Somit stimmt meine Funktion nicht so ganz?
Wie ungenau könne ndiese Werte werden?


In meinen Tests haben alle Ergebnisse bisher gestimmt.

Lieben Gruß


Smartie
Asgar
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 160

XP Home Edition
D5
BeitragVerfasst: Mo 27.06.05 13:59 
ich hab noch nie was davon gehört das die round funktion ungenau rechnet
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Mo 27.06.05 14:16 
dann war's die RoundTo...
Noch mal der Link:
qc.borland.com/wc/qcmain.aspx?d=8070
Smartie Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 205



BeitragVerfasst: Mo 27.06.05 14:27 
Ja, habs mir schon angesehn, aber, es hätt ja sein können, das auch die round betroffen ist.

Aber herzlichen dank für den tipp, ich werde also auch in zukunft lieber das ganze zu fuß machen *g*

Herzlichst lieben Gruß

Smartie
Holgerwa
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 325

WIN XP Pro, Vista Business
Delphi 7 Pro, BDS 2006 Pro
BeitragVerfasst: Mo 27.06.05 14:32 
Hallo,

wenn da etwas unklar ist, dann könnte man das Round umgehen:
ausblenden Delphi-Quelltext
1:
a := Trunc ((zahl * 1000.0) + 0.5) / 1000.0;					


Holger
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Mo 27.06.05 14:38 
soweit ich mich noch erinnere, hat RoundTo falsch gerundet. und zwar wenn man eine "gerade Nachkommastelle" hatte, also z.B. 4,18 dann wurde abgerundet und wenn man eine ungerade, also z.B. 4,19 hat, dann auf oder andersherum oder etwas in der Art.
spaxxn
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 31

WinXP SP3, Win2000 SP4, Debian Sarge
D7 EE, D2006 PE, D2007 EE
BeitragVerfasst: Di 28.06.05 10:08 
hmmm, ich habe ein fibu programm geschrieben und dort roundto verwendet. mir sind nie unstimmigkeiten aufgefallen.

greetz spaxxn