AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Probleme mit prozentrechnung

Ein Thema von Gehstock · begonnen am 3. Aug 2006 · letzter Beitrag vom 3. Aug 2006
Antwort Antwort
Seite 1 von 2  1 2      
Gehstock

Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
 
Delphi 2007 Professional
 
#1

Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:12
tolerance := pnl_result.caption/100*(strtofloat(prozent)); tolerance is ne variable
prozent is ne variable
pnl_result.caption ist das ergebnis einer anderen rechnung


muss mich echt mal damit beschäftigen was genau strtofloat und floattostr
Marcel
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#2

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:16
du musst in Codezeile 532 die zahl 12 gegen die zahl 42 austauschen.

Das war deine Frage, oder?
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  Mit Zitat antworten Zitat
Benutzerbild von _frank_
_frank_

Registriert seit: 21. Feb 2003
Ort: Plauen / Bamberg
922 Beiträge
 
Delphi 3 Professional
 
#3

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:16
muss es nicht eigentlich

tolerance := strtofloat(pnl_result.caption)/100*prozent; heisen, worausgesetzt prozent ist eine Zahl (integer, real, ...)?
Weil caption ist ja ein string, welcher erst in eine Fließkommazahl umgewandelt werden muss.

War doch die frage, oder?

Gruß Frank
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#4

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:18
Zitat:
muss mich echt mal damit beschäftigen was genau strtofloat und floattostr
Ein kleiner Tipp, wenn du mal keien Ahnung hast, was eine Funktion macht, schau einfach mal in die Delphi-Hilfe
Aber in diesem Fall sagt die Namen der Funktionen doch aus, was sie machen
StrToFloat = String To Float = Von String Nach Gleitkommazahl wandeln.

Die andere Funktion verat ich die nicht
Markus Kinzler
  Mit Zitat antworten Zitat
Gehstock

Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
 
Delphi 2007 Professional
 
#5

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:25
Hab ja schon viel geschafft auch wenn der code mit sicherheit noch besser zu lösen ist


Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
wert : string;
wiederstand : string;
tolerance: string;
prozent: string;

begin
if rb_4rings.Checked then begin
wert := floattostr(((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex);
if cb_ring3.ItemIndex = 0 then wiederstand := floattostr((strtofloat(wert)/100));
if cb_ring3.ItemIndex = 1 then wiederstand := floattostr((strtofloat(wert)/10));
if cb_ring3.ItemIndex = 2 then wiederstand := floattostr((strtofloat(wert)*1));
if cb_ring3.ItemIndex = 3 then wiederstand := floattostr((strtofloat(wert)*10));
if cb_ring3.ItemIndex = 4 then wiederstand := floattostr((strtofloat(wert)*100));
if cb_ring3.ItemIndex = 5 then wiederstand := floattostr((strtofloat(wert)*1000));
if cb_ring3.ItemIndex = 6 then wiederstand := floattostr((strtofloat(wert)*10000));
if cb_ring3.ItemIndex = 7 then wiederstand := floattostr((strtofloat(wert)*100000));
if cb_ring3.ItemIndex = 8 then wiederstand := floattostr((strtofloat(wert)*1000000));
if cb_ring3.ItemIndex = 9 then wiederstand := floattostr((strtofloat(wert)*10000000));
end;

if rb_5rings.Checked then begin
wert := floattostr(((cb_ring1.ItemIndex+1)*100) + ((cb_ring2.ItemIndex)*10) + (cb_ring53.ItemIndex));
if cb_ring54.ItemIndex = 0 then wiederstand := floattostr((strtofloat(wert)/100));
if cb_ring54.ItemIndex = 1 then wiederstand := floattostr((strtofloat(wert)/10));
if cb_ring54.ItemIndex = 2 then wiederstand := floattostr((strtofloat(wert)*1));
if cb_ring54.ItemIndex = 3 then wiederstand := floattostr((strtofloat(wert)*10));
if cb_ring54.ItemIndex = 4 then wiederstand := floattostr((strtofloat(wert)*100));
if cb_ring54.ItemIndex = 5 then wiederstand := floattostr((strtofloat(wert)*1000));
if cb_ring54.ItemIndex = 6 then wiederstand := floattostr((strtofloat(wert)*10000));
if cb_ring54.ItemIndex = 7 then wiederstand := floattostr((strtofloat(wert)*100000));
if cb_ring54.ItemIndex = 8 then wiederstand := floattostr((strtofloat(wert)*1000000));
if cb_ring54.ItemIndex = 9 then wiederstand := floattostr((strtofloat(wert)*10000000));
end;
begin
if StrTofloat(wiederstand)>999000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/
1000000))+' MOhm');
pnl_worstcasemin.caption := (floattostr((strtofloat(wiederstand)/ //soll später die minimale toleranz werden
1))+' Ohm');
pnl_worstcasemax.caption := (floattostr((strtofloat(wiederstand)/ //soll später die maximale toleranz werden
1))+' Ohm');
end;
if StrTofloat(wiederstand)>999 then begin
if StrTofloat(wiederstand)<1000000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/
1000))+' KOhm');
pnl_worstcasemin.caption := (floattostr((strtofloat(wiederstand)/ //soll später die minimale toleranz werden
1))+' Ohm');
pnl_worstcasemax.caption := (floattostr((strtofloat(wiederstand)/ //soll später die maximale toleranz werden
1))+' Ohm');
end;
end;
if StrTofloat(wiederstand)<1000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/
1))+' Ohm');
pnl_worstcasemin.caption := (floattostr((strtofloat(wiederstand)/ //soll später die minimale toleranz werden
1))+' Ohm');
pnl_worstcasemax.caption := (floattostr((strtofloat(wiederstand)/ //soll später die maximale toleranz werden
1))+' Ohm');

end;
tolerance := strtofloat(pnl_result.caption)/100*(prozent); // hier die rechnung



if rb_4rings.Checked then begin
if cb_ring4.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '10%';
prozent:=floattostr(10); // muss bestmmt alles strtofloat
end;
if cb_ring4.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=floattostr(5);
end;
if cb_ring4.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=floattostr(1);
end;
if cb_ring4.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=floattostr(2);
if cb_ring4.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=floattostr(0.5);
end;
if cb_ring4.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=floattostr(0.25);
end;
if cb_ring4.ItemIndex = 6 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=floattostr(0.1);
end;
end;
if rb_5rings.Checked then begin
if cb_ring55.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=floattostr(5);
end;
if cb_ring55.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=floattostr(1);
end;
if cb_ring55.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=floattostr(2);
end;
if cb_ring55.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=floattostr(0.5);
end;
if cb_ring55.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=floattostr(0.25);
end;
if cb_ring55.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=floattostr(0.1);
end;
end;
end;
end;
end;
nich meckern es soll nur laufen bin ja noch am lernen
Marcel
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:27
Es wäre einfacher, wenn du akurate Typen verwenden würdest, dann würde auch das ständige Casten entfallen.
Markus Kinzler
  Mit Zitat antworten Zitat
Gehstock

Registriert seit: 28. Jan 2006
Ort: Görlitz / Sachsen
489 Beiträge
 
Delphi 2007 Professional
 
#7

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 19:59
Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
wert : string;
wiederstand : string;
//tolerance: string;
prozent: string;

begin
if rb_4rings.Checked then begin
wert := floattostr(((cb_ring1.ItemIndex+1)*10) + cb_ring2.ItemIndex);
if cb_ring3.ItemIndex = 0 then wiederstand := floattostr((strtofloat(wert)/100));
if cb_ring3.ItemIndex = 1 then wiederstand := floattostr((strtofloat(wert)/10));
if cb_ring3.ItemIndex = 2 then wiederstand := floattostr((strtofloat(wert)*1));
if cb_ring3.ItemIndex = 3 then wiederstand := floattostr((strtofloat(wert)*10));
if cb_ring3.ItemIndex = 4 then wiederstand := floattostr((strtofloat(wert)*100));
if cb_ring3.ItemIndex = 5 then wiederstand := floattostr((strtofloat(wert)*1000));
if cb_ring3.ItemIndex = 6 then wiederstand := floattostr((strtofloat(wert)*10000));
if cb_ring3.ItemIndex = 7 then wiederstand := floattostr((strtofloat(wert)*100000));
if cb_ring3.ItemIndex = 8 then wiederstand := floattostr((strtofloat(wert)*1000000));
if cb_ring3.ItemIndex = 9 then wiederstand := floattostr((strtofloat(wert)*10000000));
end;

if rb_5rings.Checked then begin
wert := floattostr(((cb_ring1.ItemIndex+1)*100) + ((cb_ring2.ItemIndex)*10) + (cb_ring53.ItemIndex));
if cb_ring54.ItemIndex = 0 then wiederstand := floattostr((strtofloat(wert)/100));
if cb_ring54.ItemIndex = 1 then wiederstand := floattostr((strtofloat(wert)/10));
if cb_ring54.ItemIndex = 2 then wiederstand := floattostr((strtofloat(wert)*1));
if cb_ring54.ItemIndex = 3 then wiederstand := floattostr((strtofloat(wert)*10));
if cb_ring54.ItemIndex = 4 then wiederstand := floattostr((strtofloat(wert)*100));
if cb_ring54.ItemIndex = 5 then wiederstand := floattostr((strtofloat(wert)*1000));
if cb_ring54.ItemIndex = 6 then wiederstand := floattostr((strtofloat(wert)*10000));
if cb_ring54.ItemIndex = 7 then wiederstand := floattostr((strtofloat(wert)*100000));
if cb_ring54.ItemIndex = 8 then wiederstand := floattostr((strtofloat(wert)*1000000));
if cb_ring54.ItemIndex = 9 then wiederstand := floattostr((strtofloat(wert)*10000000));
end;
begin
if StrTofloat(wiederstand)>999000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/
1000000))+' MOhm');
{pnl_worstcasemin.caption := (floattostr(((strtofloat(wiederstand)-tolerance)/
1000000))+' MOhm');
pnl_worstcasemax.caption := (floattostr(((strtofloat(wiederstand)+tolerance)/
1000000))+' MOhm');   }

end;
if StrTofloat(wiederstand)>999 then begin
if StrTofloat(wiederstand)<1000000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/
1000))+' KOhm');
{pnl_worstcasemin.caption := (floattostr(((strtofloat(wiederstand)-tolerance)/
1000))+' KOhm');
pnl_worstcasemax.caption := (floattostr(((strtofloat(wiederstand)+tolerance)/
1000))+' KOhm');     }

end;
end;
if StrTofloat(wiederstand)<1000 then begin
pnl_result.caption := (floattostr((strtofloat(wiederstand)/
1))+' Ohm');
{pnl_worstcasemin.caption := (floattostr(((strtofloat(wiederstand)-tolerance)/
1))+' Ohm');
pnl_worstcasemax.caption := (floattostr(((strtofloat(wiederstand)+tolerance)/
1))+' Ohm');        }

end;
//tolerance := strtofloat(pnl_result.caption)/100*(prozent);



if rb_4rings.Checked then begin
if cb_ring4.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '10%';
prozent:=floattostr(10);
end;
if cb_ring4.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=floattostr(5);
end;
if cb_ring4.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=floattostr(1);
end;
if cb_ring4.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=floattostr(2);
if cb_ring4.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=floattostr(0.5);
end;
if cb_ring4.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=floattostr(0.25);
end;
if cb_ring4.ItemIndex = 6 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=floattostr(0.1);
end;
end;
if rb_5rings.Checked then begin
if cb_ring55.ItemIndex = 0 then begin
pnl_Tolerance.Caption:= '5%';
prozent:=floattostr(5);
end;
if cb_ring55.ItemIndex = 1 then begin
pnl_Tolerance.Caption:= '1%';
prozent:=floattostr(1);
end;
if cb_ring55.ItemIndex = 2 then begin
pnl_Tolerance.Caption:= '2%';
prozent:=floattostr(2);
end;
if cb_ring55.ItemIndex = 3 then begin
pnl_Tolerance.Caption:= '0,5%';
prozent:=floattostr(0.5);
end;
if cb_ring55.ItemIndex = 4 then begin
pnl_Tolerance.Caption:= '0,25%';
prozent:=floattostr(0.25);
end;
if cb_ring55.ItemIndex = 5 then begin
pnl_Tolerance.Caption:= '0,1%';
prozent:=floattostr(0.1);
end;
end;
end;
end;
end;


kannst du mir bitte trotzdem helfen
Marcel
  Mit Zitat antworten Zitat
mkinzler
(Moderator)

Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.851 Beiträge
 
Delphi 11 Alexandria
 
#8

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 20:10
Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
wert : Extended;
widerstand : Extended;
tolerance: Extended;
prozent: Extended;

begin
    if rb_4rings.Checked then
    begin
        wert := (cb_ring1.ItemIndex+1)*10 + cb_ring2.ItemIndex;
        case cb_ring3.ItemIndex of
          0: widerstand := wert / 100;
          1: widerstand := wert /10;
          2: widerstand := wert;
          3: ...
end;
...
Markus Kinzler
  Mit Zitat antworten Zitat
Benutzerbild von _frank_
_frank_

Registriert seit: 21. Feb 2003
Ort: Plauen / Bamberg
922 Beiträge
 
Delphi 3 Professional
 
#9

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 20:25
Zitat von Gehstock:
...
bitte gewöhne dir ordentliche code-formatierung (Einrückung) an...

(mal davon abgesehen schreibt man widerstand ohne 'e' )

Delphi-Quellcode:
procedure TForm2.btn_executeClick(Sender: TObject);
var
  wert : integer;
  widerstand,prozent,tolerance : double;
  einheit:string;
begin
  if rb_4rings.Checked then
  begin
    wert := (cb_ring1.ItemIndex+1)*10 + cb_ring2.ItemIndex;
    case cb_ring3.ItemIndex of
      0: widerstand := wert/100;
      1: widerstand := wert/10;
      2: widerstand := wert;
      3: widerstand := wert*10;
      4: widerstand := wert*100;
      5: widerstand := wert*1000;
      6: widerstand := wert*10000;
      7: widerstand := wert*100000;
      8: widerstand := wert*1000000;
      9: widerstand := wert*10000000));
    end;

...

  //widerstandswert ausgeben (2 nachkommastellen)
  if wiederstand>999000 then
  begin
    widerstand:=widerstand / 1000000;
    Einheit:='MOhm';
  end else if ...

  pnl_result.caption := format ('%.2f '+einheit,[widerstand]);


...

  if rb_4rings.Checked then
  begin
    case cb_ring4.ItemIndex of
      0: prozent:=10;
      1: prozent:=5;
      2: prozent:=1;
      3: prozent:=2;
      4: prozent:=0.5;
      5: prozent:=0.25;
      6: prozent:=0.1;
    end;
  end;

  if rb_5rings.Checked then
  begin
    case cb_ring55.ItemIndex of
      0: prozent:=5;
      1: prozent:=1;
      2: prozent:=2;
      3: prozent:=0.5;
      4: prozent:=0.25;
      5: prozent:=0.1;
    end;
  end;
  pnl_Tolerance.Caption:= FloatToStr(prozent)+' %';
  tolerance := wiederstand/100*prozent;
  pnl_worstcasemin.caption := floattostr(wiederstand-tolerance)+' '+Einheit);
  pnl_worstcasemax.caption := floattostr(wiederstand+tolerance)+' '+Einheit);
end;
HTH Frank
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#10

Re: Probleme mit prozentrechnung

  Alt 3. Aug 2006, 20:38
Hallo,

hier noch ein thread zum gleichen Thema: klick

Gute Nacht

marabu
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:49 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz