Similar to StrToFloat, the FloCurrStrToFloat function converts a String containing both numeric and currency characters into a Float data type, by removing the non-numeric characters.

FloCurrStrToFloat will fail if the Windows decimal symbol is not a decimal full-stop (.).

If the remaining characters do not represent a valid numeric currency value, an error will occur. If this occurs, you could use a Try...Except block to handle the error and provide a default value.

Declaration: Function FloCurrStrToFloat( const S : string) : Extended

An example to try follows.

procedure ScriptEvent(var Value:Variant);
var
s2, s3 : String;
 
begin
s2 := '$1,234.567';
//Value will be equal to 1234.567
Value := FloCurrStrToFloat(s2);
LogInfo('FloCurrStrToFloat(' + s2 + ')->' + FloatToStr(FloCurrStrToFloat(s2)));
LogInfo('');
s2 := '$1.234,567';
//Value will be equal to 1.234567 - the "." is taken as the decimal symbol
//"+", "-", and digits are left intact, and all other characters are removed
Value := FloCurrStrToFloat(s2);
LogInfo('FloCurrStrToFloat(' + s2 + ')->' + FloatToStr(FloCurrStrToFloat(s2)));
LogInfo('');
 
s3 := 'USD 1 , 2 3 4 . 5 6 ';
LogInfo('FloCurrStrToFloat(' + s3 + ')->' + FloatToStr(FloCurrStrToFloat(s3)));
s3 := '+ 1 , 2 3 4 . 5 6 ';
LogInfo('FloCurrStrToFloat(' + s3 + ')->' + FloatToStr(FloCurrStrToFloat(s3)));
s3 := '- 1 , 2 3 4 . 5 6 ';
LogInfo('FloCurrStrToFloat(' + s3 + ')->' + FloatToStr(FloCurrStrToFloat(s3)));
s3 := '1 , 2 3 4 . 5 6-'; // fails
try
strResult := FloatToStr(FloCurrStrToFloat(s3));
except
strResult := 'Exception: ' + ExceptionToString(ExceptionType, ExceptionParam);
end;
LogInfo('FloCurrStrToFloat(' + s3 + ')->' + strResult);
LogInfo('');
 
end;