Delphi-PRAXiS
Seite 2 von 3     12 3      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Fehler bei StrToFloat(StrAlsIntegerFormatiert) (https://www.delphipraxis.net/90376-fehler-bei-strtofloat-stralsintegerformatiert.html)

newgro 16. Apr 2007 13:52

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Im Debug Inspector steht
value '1.274.847'

newgro 16. Apr 2007 13:54

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Ja, ok. Deshalb auch der Betreff. Kann ich denn mit Delphi aus einem IntegerString ein Float machen?

mkinzler 16. Apr 2007 13:56

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Dann setzte doch das Format kurzzeitig um:
Delphi-Quellcode:
ThousandSeparator = '.';
toFormat:= StrToFloat(value);

newgro 16. Apr 2007 14:02

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Gesagt, getan. Und wieder der FormatError.

mkinzler 16. Apr 2007 14:04

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Schon die überladene StrToFloat mit Format versucht?

newgro 16. Apr 2007 14:08

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Hatte
Delphi-Quellcode:
function Tfrm_budgets.getFormatted(value: String; decPlaces: Integer): Real;
var toFormat: Real;
f: TFormatSettings;
begin
  if value = '' then
    toFormat:= 0
  else begin
    f.ThousandSeparator:= '.';
    f.DecimalSeparator:= ',';
    toFormat:= StrToFloat(value, f);
  end;
  result:=StrToFloat(format('%.' + IntToStr(decPlaces) + 'n', [toFormat]));
end;
probiert und es ging nicht.

newgro 16. Apr 2007 15:50

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Habe ein bischen weiter geforscht und dabei heraus bekommen, das es tatsächlich am TausenderTrennzeichen liegt.
Aber wie kann ich den . nun löschen? So wie ich es mache geht es nicht:

Delphi-Quellcode:
function TestTfrm_budgets.getFormatted(value: String; decPlaces: Integer): Real;
var toFormat: Real;
    i: Integer;
    str: String;
    f: TFormatSettings;
begin
  if value = '' then
    toFormat:= 0
  else begin
    for i := 0 to length(value) do
    begin
      v:= ;
      if (value[i] <> f.ThousandSeparator) then
      begin
       str:= str + value[i];
      end;
    end;
    toFormat:= StrToFloat(str);
  end;
  result:=StrToFloat(format('%.' + IntToStr(decPlaces) + 'n', [toFormat]));
end;
So steht trotzdem der Punkt (TausenderTrenner) drin.

mkinzler 16. Apr 2007 16:00

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
StringReplace()

newgro 16. Apr 2007 16:08

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Delphi-Quellcode:
function TestTfrm_budgets.getFormatted(value: String; decPlaces: Integer): Real;
var toFormat: Real;
    i: Integer;
    str: String;
    f: TFormatSettings;
begin
  if value = '' then
    toFormat:= 0
  else begin
    str:= StringReplace(value, f.ThousandSeparator, '', [rfReplaceAll]);
    toFormat:= StrToFloat(str);
  end;
  result:=StrToFloat(format('%.' + IntToStr(decPlaces) + 'n', [toFormat]));
end;
Und wieder der Fehler. Aber er ersetzt nicht den ThousendSeparator. Muss ich den irgendwie umwandeln?

Danke
Per

mkinzler 16. Apr 2007 16:16

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
 
Delphi-Quellcode:
str:= StringReplace(value, '.', '', [rfReplaceAll]);


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:48 Uhr.
Seite 2 von 3     12 3      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz