Autor Beitrag
JustusJonas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 06.02.06 16:28 
Hi,

ich habe einen String der folgendermaßen aufgebaut ist: ###.## (wobei # jede mögliche Ziffer sein kann).
Nun möchte ich diesen String so in eine Gleitkommazahl umwandeln, dass ich damit rechnen kann.

Ich hab TextToFloat schon probiert, schaffe es damit aber nicht, da eine total wissenschaftliche Zahl dabei rauskommt.

Jemand eine Lösung für mich?

Greetz
starsurfer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 334

Win 95, Win 98, Win XP, Win Vista, Linux
D5 Enterprise ,D2005, D6 Personal, Visual C++ Express 2005, C++ Builder 6 E, Dev-C++
BeitragVerfasst: Mo 06.02.06 16:32 
strtofloat
oder
strtofloatf

_________________
GEIZ IST GEIL! - Ihr Sozialamt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 06.02.06 16:32 
Was meinst du mit "da kommt ne total wissenschaftliche Zahl bei raus"? Ein Float ist ein Float. Die Anzeige ist allerdings standardmäßig tatsächlich nocht "123.45", sondern anders. Aber da hilft dann FormatFloat.

_________________
We are, we were and will not be.
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mo 06.02.06 16:34 
So geht das ganz prächtig:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var
   rValue: real;
   strValue: string;
begin
   //initialisieren
   strValue := '1.2345';
   
   //Dezimalseparator anpassen
   strValue := stringreplace(strValue, '.', DecimalSeparator, [rfReplaceAll]);
   strValue := stringreplace(strValue, ',', DecimalSeparator, [rfReplaceAll]);

   //umwandeln
   try
      rValue := strtofloat(strValue);
   except
      rValue := 0;
   end;
end;


Beste Grüße
Tastaro
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Mo 06.02.06 18:27 
Danke, das hat mir schon ausreichend geholfen! :)

Greetz