I need some calculator with Delphi and sometimes my number include '<' and '>'. I need to store them for after usage. For example:
fnc_ProcessNumber('0.320>','100',multiplication)
This needs to give this output: 320>, but this line fails:
boolControl := ContainsText(strEnteredResult,[lessThan,greaterThan]);
I also try this:
boolControl := IndexStr(strEnteredResult,[lessThan,greaterThan]);
Here's my code and type.
type TMaths = (addition,subtraction,multiplication,division);
function fnc_ProcessNumber(strEnteredResult,strProcessedNumber:string;Math:TMaths) : string;
const lessThan : string = '<';
const greaterThan : string = '>';
var
intIndexCounter,intIndexMath:Integer;
extNewResult:Extended;
boolControl,boolLess,boolGreater:Boolean;
begin
Result := 'null';
boolControl := ContainsText(strEnteredResult,[lessThan,greaterThan]);
if boolControl then
begin
case intIndexCounter of
0:
begin
intIndexMath := AnsiPos(lessThan,strEnteredResult);
boolLess := True;
end;
1:
begin
intIndexMath := AnsiPos(greaterThan,strEnteredResult);
boolGreater := True;
end;
end;
strProcessedNumber := Copy(strEnteredResult,intIndexMath,1);
end
else
begin
extNewResult := StrToFloat(strEnteredResult);
end;
case Math of
addition:
begin
extNewResult := extNewResult + StrToFloat(strProcessedNumber);
end;
subtraction:
begin
extNewResult := Abs(extNewResult - StrToFloat(strProcessedNumber));
end;
multiplication:
begin
extNewResult := extNewResult * StrToFloat(strProcessedNumber);
end;
division:
begin
extNewResult := extNewResult / StrToFloat(strProcessedNumber);
end;
end;
Result := FloatToStr(extNewResult);
if boolLess then Result := lessThan+Result;
else if boolGreater then Result := Result+greaterThan;
end;