Str2Float Function
Converts a string into an Extended.

Unit
QESBPCSConvert

Declaration
Function Str2Float(const S: string): Extended;

Description
Removes Thousand Separators if they are present as well as any leading or trailing white spaces (ie <= #32). Non-numeric will return 0 unless you set ESBRaiseFloatError to true.

Also ignores Percentage Signs (%).

Parameters
the String to process

Category
String/Float Conversion Routines

Implementation

function Str2Float (const S: string): Extended;
var
     S2: string;
     Found: Boolean;
begin
     try
          S2 := Trim (StripThousandSeparators (StripPercent (S)));
          if S2 = '' then
               Result := 0.0
          else
          begin
               repeat
                    Found := False;
                    if S2 [Length (S2)] in ['e', 'E', DecimalSeparator, '-', '+'] then
                    begin
                         S2 := LeftStr (S2, Length (S2) - 1);
                         Found := True;
                         S2 := Trim (S2);
                    end;
               until not Found or (S2 = '');
               if S2 = '' then
                    Result := 0.0
               else
                    Result := StrToFloat (S2);
          end;
     except
          if ESBRaiseFloatError then
               raise
          else
               Result := 0;
	end;
End;


HTML generated by Time2HELP
http://www.time2help.com