那就自己写个函数吧。 Function Fun_Compare(Ad_a: double; Ad_b: double; As_Op: string; Ai_precision: longint) : Boolean ; begin if As_Op= '=' then if Round(Ad_A*Ai_precision) = Round(Ad_b*Ai_precision) then Result := true else result := False; if As_Op= '>' then if Round(Ad_A*Ai_precision) > Round(Ad_b*Ai_precision) then Result := true else result := false; if As_Op= '<' then if Round(Ad_A*Ai_precision) < Round(Ad_b*Ai_precision) then Result := true else result := false; if As_Op= '<>' then if Round(Ad_a*Ai_precision) <> Round(Ad_b*Ai_precision) then Result := true else result := false; if As_Op= '>=' then if Round(Ad_A*Ai_precision) >= Round(Ad_b*Ai_precision) then Result := true else result := false; if As_Op= '<=' then if Round(Ad_A*Ai_precision) <= Round(Ad_b*Ai_precision) then Result := true else result := false; end;
你可以通过传递一个函数来解决。或者就像楼上说的,用Case。
Function Fun_Compare(Ad_a: double; Ad_b: double; As_Op: string; Ai_precision: longint) : Boolean ;
begin
if As_Op= '=' then
if Round(Ad_A*Ai_precision) = Round(Ad_b*Ai_precision) then
Result := true
else
result := False;
if As_Op= '>' then
if Round(Ad_A*Ai_precision) > Round(Ad_b*Ai_precision) then
Result := true
else
result := false;
if As_Op= '<' then
if Round(Ad_A*Ai_precision) < Round(Ad_b*Ai_precision) then
Result := true
else
result := false;
if As_Op= '<>' then
if Round(Ad_a*Ai_precision) <> Round(Ad_b*Ai_precision) then
Result := true
else
result := false;
if As_Op= '>=' then
if Round(Ad_A*Ai_precision) >= Round(Ad_b*Ai_precision) then
Result := true
else
result := false;
if As_Op= '<=' then
if Round(Ad_A*Ai_precision) <= Round(Ad_b*Ai_precision) then
Result := true
else
result := false;
end;