Autor Beitrag
bluecat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Di 17.05.05 16:51 
Hallo leute!
ich habe ein Problem ich kann FloatToStr nicht verwenden, bei n=40 hat den cod Problem, deswegen muss ich den Variant nehme.diese Lösung ist auch nicht gut, da das program nur n bis 10 fehlerfrei läuft. Kann jemand mir sagen warum khann ich nicht verwenden.
Danke im voraus!

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
function InputVektor: real;
var i:integer;
//label Beispielwert;
begin
Randomize;
for i:=0 to High(Vektor)-1 do
 begin
  Vektor[i]:=random(2501)-random(5001);
 end
end;
  
procedure TMainForm.ScanAlgClick(Sender: TObject);
var MaxSoFar,MaxEndingHere:Real;
    i: Longint;
    a,b,c: Int64;
    Ergebnis:Variant;
begin
QueryPerformanceFrequency(a);
QueryPerformanceCounter(b);
MaxSoFar:=0;
MaxEndingHere:=0;
 for i:= 0 to n-1 do
    Begin
      MaxEndingHere:=max(MaxEndingHere+Vektor[i],0);
      MaxSoFar:=max(MaxSoFar,MaxEndingHere);
    end;
QueryPerformanceCounter(c);
MainForm.SCALaufzeit.Text:=IntToStr((c - b) * 1000000000 div a);
Ergebnis:=MaxSoFar;
MainForm.SCAErg.Text:=Ergebnis;

end;


Moderiert von user profile iconChristian S.: Quote- durch Delphi-Tags und b- durch highlight-Tags ersetzt
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Di 17.05.05 18:18 
Titel: FloatToStr funktioniert nicht
Hi,
leider habe ich absolut nicht verstanden, was bei dir nicht funktioniert.
Was erwartest du zu bekommen, und was bekommst du?
Was ist das überhaupt, was du dort programmiert hast? Wofür wird es eingesetzt?
crakos
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 195


D2k5 Pers
BeitragVerfasst: Di 17.05.05 18:37 
also was ich denke, warum das bei dir nicht geht, welcher Typ is n ???
ich Wette, das das eine integer variable ist, richtig???
schließe ich mal aus
ausblenden Delphi-Quelltext
1:
 for i:= 0 to n-1 do					

und dann ist FloatToStr die falsche funktion, da du eine real zahl in einen string umwandelst. du musst IntToStr benutzen ;)
[Alles unter vorbehalt]

_________________
Das Ende der Menschheit ist der Anfang der Unendlichkeit.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Di 17.05.05 18:39 
Zum Code:
ausblenden Delphi-Quelltext
1:
2:
Ergebnis:=MaxSoFar;
MainForm.SCAErg.Text:=Ergebnis;

Warum wiest du den Wert überhaupt zuerts de4r Variable ERgebniss zu?

Wieso nicht einfach so:
ausblenden Delphi-Quelltext
1:
MainForm.SCAErg.Text:=FloatToStr(MaxSoFar);					

Ich weis net ob das unter den hier gegebenen Umständen hilft, da ich deien Frage auch net kapiert hab, aber versuch's halt mal.
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Di 17.05.05 18:45 
Titel: Float-Zahl (extended) incl. Rundung in String umwandeln
Willst du tatsächlich eine Float-Zahl, also vom Typ Extended, in einen String umwandeln? Wenn ja, soll er dann im Nachkommabereich auch noch gerundet werden?
Wenn auch ja, dann habe ich eine Funktion dafür. Sie lautet

FloatToStrWaehrung( neBetrag : extended; niStellen : integer ) : string;

Hilft dir das vielleicht weiter?