我要一个四舍五入的函数。原代码。谢谢大家帮忙。
//*************************************************
// 四舍五入函数
// 参数说明: xInput:四舍五入前浮点数
// WS: 四舍五入精确位置数
// Result:返回四舍五入后浮点数
function DataVerify(xInput:Double;WS:Integer):Double;
begin
end;
//*************************************************
// 四舍五入函数
// 参数说明: xInput:四舍五入前浮点数
// WS: 四舍五入精确位置数
// Result:返回四舍五入后浮点数
function DataVerify(xInput:Double;WS:Integer):Double;
begin
end;
Mathtype TRoundToRange = -37..37;
function RoundTo(const AValue: Double; const ADigit: TRoundToRange): Double;
var
LFactor: Double;
begin
LFactor := IntPower(10, ADigit);
Result := Round(AValue / LFactor) * LFactor;
end;
var
i:integer;
sty,First_Data,last_Data,y,AddNum:string;
Add:Double;
begin
sty:=floattostr(xInput);
if POS('.',sty)>0 then
begin
First_Data:=copy(sty,1,pos('.',sty)-1);
last_Data:=copy(sty,pos('.',sty)+1,length(sty)-pos('.',sty));
if Length(last_Data)<=WS then
Result:=xInput
else begin
y:=copy(last_Data,WS+1,1);
if strtoint(y)>4 then
begin
Add:=1;
for i:=1 to WS do
Add:=Add/10;
Result:=strtofloat(First_Data+'.'+copy(Last_Data,1,WS))+Add;
end
else begin
Result:=strtofloat(First_Data+'.'+copy(Last_Data,1,WS))
end;
end;
end
else Result:=xInput
end;