var s:string; begin s:=formatfloat('0.00',a / b); end;
下面的代码可将x保留小数点后i位,对第i+1位进行4舍五入, 返回的是实数。 function myRound(x:real; i:integer) : real; var fact : integer; begin fact:=1; while( i>0 ) do begin fact:=fact*10; i:=i-1; end; myRound := round(x*fact)/fact; end;转化为字符串可用floattostr()
Function Change(a,b:double): string; begin if b=0 then exception.create('error') else result:= formatfloat('0.00',a/b);end;
fuction myprogram(x,y); var t:integer; begin t:=fromat('0.00,x/y); myprogram:=t; end;
begin
s:=formatfloat('0.00',a / b);
end;
返回的是实数。
function myRound(x:real; i:integer) : real;
var
fact : integer;
begin
fact:=1;
while( i>0 ) do begin
fact:=fact*10;
i:=i-1;
end;
myRound := round(x*fact)/fact;
end;转化为字符串可用floattostr()
begin
if b=0 then exception.create('error')
else
result:= formatfloat('0.00',a/b);end;
var
t:integer;
begin
t:=fromat('0.00,x/y);
myprogram:=t;
end;
有问题请发信息到我的E-mail:[email protected]