procedure TForm1.Button2Click(Sender: TObject);
begin
Edit3.Text:=FloatToStr(MyRound(StrToFloat(Edit1.Text),StrToInt(Edit2.Text)));
end;
function TForm1.MyRound(x:extended;n :integer) : Double; //x 浮点数,n 整数保留的位数,返
回还是浮点
function RoundEx (const Value: Double): integer;
var
y: Real;
begin
y := Value - Trunc(Value);
if y >= 0.5 then
Result := Trunc(Value) + 1
else
Result := Trunc(Value);
end;
begin
if n=0 then
result := RoundEx(x)
else
begin
result := x * exp(n*ln(10));
result := RoundEx(result);
result := result /exp(n*ln(10));
end;
end;