【发布时间】:2022-01-08 11:07:13
【问题描述】:
我需要一些 Delphi 计算器,有时我的号码包括 '<' 和 '>'。我需要储存它们以备后用。例如:
fnc_ProcessNumber('0.320>','100',multiplication)
这需要给出这个输出:320>,但是这一行失败了:
boolControl := ContainsText(strEnteredResult,[lessThan,greaterThan]);
我也试试这个:
boolControl := IndexStr(strEnteredResult,[lessThan,greaterThan]);
这是我的代码和类型。
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;
【问题讨论】:
-
对于您的下一个问题,请尝试隔离一个单个问题。例如,“给定一个字符串 S 和一个字符串数组 Arr,我如何找出 Arr 中是否存在一个元素 A,使得 A 是 S 的子字符串”,甚至没有提到计算器部分。
-
不应该是 32> 而不是 320>