![]() |
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Im Debug Inspector steht
value '1.274.847' |
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Ja, ok. Deshalb auch der Betreff. Kann ich denn mit Delphi aus einem IntegerString ein Float machen?
|
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Dann setzte doch das Format kurzzeitig um:
Delphi-Quellcode:
ThousandSeparator = '.';
toFormat:= StrToFloat(value); |
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Gesagt, getan. Und wieder der FormatError.
|
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Schon die überladene StrToFloat mit Format versucht?
|
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Hatte
Delphi-Quellcode:
probiert und es ging nicht.
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; |
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:
So steht trotzdem der Punkt (TausenderTrenner) drin.
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; |
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
StringReplace()
|
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Delphi-Quellcode:
Und wieder der Fehler. Aber er ersetzt nicht den ThousendSeparator. Muss ich den irgendwie umwandeln?
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; Danke Per |
Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)
Delphi-Quellcode:
str:= StringReplace(value, '.', '', [rfReplaceAll]);
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 17:48 Uhr. |
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