求一四舍五入的函数,E文不太好,不想找了...(20分)

  • 主题发起人 主题发起人 找不着北
  • 开始时间 开始时间

找不着北

Unregistered / Unconfirmed
GUEST, unregistred user!
如题!我想计算字段的值,它是3位小数的,我想将第三位舍掉并向前进一,该用哪个函数呢?
 
formatfloat()
 
Round() only returns an integer.

formatFloat() shoule be the correct one.
 
Try this one if you want:

procedure TForm2.btnCalculate(Sender: TObject);
var
r:real;
i:integer;
begin
r:=12.3054; //if r:=12.3059, it should return 12.306
r:=r*1000;
r:=round(r);
i:=trunc(r);
r:=i/1000;
end;
 
formatfloat('0.00',123.345)
 
r,m:REAL;
m:=r*1000;
if r*1000-trunc(m)>0 then m:=m+1;
result:=trunc(m)/1000;
 
function RMRound(x: Extended; dicNum: Integer): Extended; //四舍五入
var
tmp: string;
i: Integer;
begin
tmp := '#.';
for i := 1 to dicNum do
tmp := tmp + '0';
Result := StrToFloat(FormatFloat(tmp, x));
end;
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
926
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部