Einzelnen Beitrag anzeigen

newgro

Registriert seit: 26. Mär 2007
53 Beiträge
 
Delphi 2006 Professional
 
#21

Re: Fehler bei StrToFloat(StrAlsIntegerFormatiert)

  Alt 16. Apr 2007, 16:27
Dies ist der Testfall. Und der geht auch wieder nicht. So langsam denke ich an Selbstmord (
Delphi-Quellcode:
procedure TestTfrm_budgets.TestgetFormatted1;
var
  ReturnValue: Real;
  decPlaces: Integer;
  value: string;
begin
  value:='1.000,00';
  ReturnValue := getFormatted(value, decPlaces);
  Assert(ReturnValue=1000.00, 'Oops');
end;

function TestTfrm_budgets.getFormatted(value: String; decPlaces: Integer): Real;
var toFormat: Real;
    str: String;
begin
  if value = 'then
    toFormat:= 0
  else begin
    str:= StringReplace(value, '.', '', [rfReplaceAll]);
    toFormat:= StrToFloat(value);
  end;
  result:=StrToFloat(format('%.' + IntToStr(decPlaces) + 'n', [toFormat]));
end;
  Mit Zitat antworten Zitat