Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Probleme mit Prozentrechnung (https://www.delphipraxis.net/75367-probleme-mit-prozentrechnung.html)

Gehstock 18. Aug 2006 12:42


Probleme mit Prozentrechnung
 
Delphi-Quellcode:
var
wert : string;
wiederstand : string;
tolerance: string;
prozent: extended;

Delphi-Quellcode:
wiederstand := floattostr((strtofloat(wert)*10000));
*****z.B.
Delphi-Quellcode:
tolerance := floattostr( (strtofloat(wiederstand)/100)*prozent);
Delphi-Quellcode:
prozent:=(1);
Und hier die rechnung für Toleranz minimum

Delphi-Quellcode:
(floattostr(((strtofloat(wiederstand)-tolerance)/
1))+' Ohm');

und maximum

Delphi-Quellcode:
(floattostr(((strtofloat(wiederstand)+tolerance)/
1))+' Ohm');

mit den Formeln hab ich so meine probleme

Klaus01 18. Aug 2006 12:49

Re: Probleme mit Prozentrechnung
 
Delphi-Quellcode:
tolerance := floattostr( (strtofloat(wiederstand)*prozent/100);
Minimum:

Delphi-Quellcode:
floattostr(strtofloat(wiederstand)-tolerance)+' Ohm');
Maximum:

Delphi-Quellcode:
floattostr(strtofloat(wiederstand)+tolerance)+' Ohm';
Kannst Du mal genauer beschreiben wo Dein Problem ist?

Grüße
Klaus

mkinzler 18. Aug 2006 12:51

Re: Probleme mit Prozentrechnung
 
Speicher dir doch vor dem Berechnen die Werte aus den Edits in einem rechenbaren Format zwischen. Dann wird das ganze um einiges übersichtlicher.
Delphi-Quellcode:
var
wert : Extended;
wiederstand : Extended;
tolerance: Extended;
prozent: extended;
sTolMin, sTolMax: string;
...
prozent:=1;
widerstand := wert*10000;
tolerance := widerstand/100*prozent;
sTolMin := FloatToStr((widerstand-tolerance)/1)+' Ohm');
sTolMax:= FloatToStr((widerstand-tolerance)/1)+' Ohm');
Und Widerstand schreibt man trotzdem ohne ie.

_frank_ 18. Aug 2006 12:54

Re: Probleme mit Prozentrechnung
 
wo ist dein problem?...die prozentformel sollte passen.
Das einzige, was ich zu bemämgeln habe (hatte ich imho schon in dem anderen thread gesagt), ist das ständige umwandeln von string in die zahlentypen (integer/extended) vice versa. Warum nicht *nur* in extended rechnen und nur zur Ausgabe in string umwandeln?
gut und das /1 kannst du dir schenken, da zahl/1=zahl

Gruß Frank


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:13 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