Autor Beitrag
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 11.08.04 16:14 
hallo
ist est irgendwie möglich die anzahl der angezeigten dezimalstellen festzulegen
variablentyp ist real.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mi 11.08.04 16:17 
Hallo

gugg dir funktionen wie z.b. format oder floattostrf an.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
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: Mi 11.08.04 16:20 
FormatFloat('0.00',AReal)Ist so ziemlich das einfachste - finde ich jedenfalls :wink:

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

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Mi 11.08.04 16:30 
wäre es auch möglich die nachkommastellen in der variable zu entfernen?
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: Mi 11.08.04 16:33 
Jein, du kannst nach der Umwandlung in einen String ja wieder ein Real draus machen (StrToFloat), allerdings finde ich das sehr unsauber. Es geht bestimmt noch einfacher :?

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Mi 11.08.04 16:41 
Da hier:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function TruncVar(variable: extended; stellen: Integer): Extended;
var tmp: extended;
begin
  tmp := power(10, stellen);
  variable := variable * tmp;
  stellen := Trunc(variable);
  result := stellen / tmp;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage(FloatToStr(TruncVar(3.141592653)));
end;

Math einbinden nicht vergessen!

raziel

_________________
JSXGraph
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mi 11.08.04 17:00 
anstelle des codes kannst du auch roundto verwednen, der ähnlich vorgeht.
Anstelle von raziel würde ich aber auch nicht trunc nehmen, sondern round. bei seiner Varinate käme 3,141 raus, wenn du auf die 3. Nachkommastelle rundest wäre es 3,142.

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Mi 11.08.04 17:18 
DarkHunter hat folgendes geschrieben:
ist est irgendwie möglich die anzahl der angezeigten dezimalstellen festzulegen

Von Runden war nie die Rede :mrgreen: ;)

_________________
JSXGraph