Autor Beitrag
Sotov
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Fr 06.10.06 22:38 
Wenn ich eine funktion gemacht habe und dabei mehrere verschiedene Werte herausgekriegt habe zb

0,24
0,056
0,0001

dann möchte ich die Zahl die 0 am nähersten ist herausnehmen und mit ihr etwas anstellen!

Wie mache ich das?
Wie kann man Delphi klar machen, dass er die 0 am nähersten stehende Zahl aus verschiedenen varianten raussuchen soll?

Danke im Voraus!


Moderiert von user profile iconGausi: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Fr 06.10.2006 um 23:05
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 06.10.06 22:41 
In dem du die zahl mit dem kleinsten Betrag ermittelst.

_________________
Markus Kinzler.


Zuletzt bearbeitet von mkinzler am Fr 06.10.06 22:42, insgesamt 1-mal bearbeitet
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Fr 06.10.06 22:41 
Die Zahl, die der 0 am nächsten ist, ist die, deren Betrag am kleinsten ist. Den Betrag kriegt man mit abs und dann einfach die kleinste Zahl suchen.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 06.10.06 22:42 
user profile iconmkinzler hat folgendes geschrieben:
In dem du die zahl mit dem kleinsten Betrag ermittelst.

Würde das nicht auf einen Sortieralgo hinauslaufen?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Sotov Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Fr 06.10.06 22:43 
Und wie ermittelt man die kleinste zahl? Wenn ich den Betrag, angenommen, schon habe?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 06.10.06 22:46 
In dem du die Liste sortierst.

_________________
Markus Kinzler.
Sotov Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Fr 06.10.06 22:49 
user profile iconmkinzler hat folgendes geschrieben:
In dem du die Liste sortierst.

Mano, könnt ihr bitte etwas genauer werden? Ich weiß es halt nicht und googeln hilft auch nicht weiter!
Was heisst Liste sortieren und wie macht man das?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 06.10.06 22:50 
Such doch mal nach QuickSort, BubbleSort, ShellSort, GnomeSort, ...

_________________
Markus Kinzler.
Sotov Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Fr 06.10.06 22:52 
das problem ist ja, dass ich keine ganzen zahlen habe, dabei hilft array auch nicht wirklich!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 06.10.06 22:55 
user profile iconSotov hat folgendes geschrieben:
das problem ist ja, dass ich keine ganzen zahlen habe, dabei hilft array auch nicht wirklich!
???

Suche in: Delphi-Forum QUICKSORT

_________________
Markus Kinzler.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 06.10.06 23:00 
Das ist z.B. Bubblesort. Der Algorithmus ist aus Wikipedia kopiert:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure bubblesort(var f: Array of Integer);
var i,j,temp: Integer;
begin
  for i:=High(f) downto Low(f)+1 do 
    for j:=Low(f)+1 to i do 
      if f[j-1] > f[j] then begin
        temp := f[j-1];
        f[j-1] := f[j];
        f[j] := temp;
      end
end;

Nun muss er noch noch auf dein Problem zugeschnitten werden, sprich auf die Listbox.
Edit: Er hat doch keine Listbox :?!?:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot


Zuletzt bearbeitet von Marco D. am Fr 06.10.06 23:07, insgesamt 1-mal bearbeitet
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8549
Erhaltene Danke: 478

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 06.10.06 23:03 
Mädels...hier will einer die betraglich kleinste Zahl finden. Da bringt Sortieren nichts, wenn man auch negative Zahlen hat, und ist ansonsten mit Kanonen auf Spatzen geschossen... :roll:

So gehts:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var MeinZahlenArray: Array of Double;
AbsMin: Double;
//...
// hier noch ein Fehler-Abfangen einbauen, wenn keine Zahl im Array ist!!
AbsMin := abs(MeinZahlenArray[0]);
for i := 1 to high(MeinZahlenArray) do
  if abs(MeinZahlenArray[i]) < AbsMin then
    AbsMin := MeinZahlenArray[i];

_________________
We are, we were and will not be.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 06.10.06 23:05 
Zitat:
Mädels...hier will einer die betraglich kleinste Zahl finden. Da bringt Sortieren nichts, wenn man auch negative Zahlen hat, und ist ansonsten mit Kanonen auf Spatzen geschossen... :roll:
Wir Redeten von den Beträgen ...

_________________
Markus Kinzler.
Sotov Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Fr 06.10.06 23:11 
OK, danke! Schon gelöst!
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Sa 07.10.06 00:15 
Na dann erzähl doch mal, wie du die Sache gelöst hast, damit Leute mit der selben oder ähnlichen Frage in zukunft auch was davon haben=)