delphi 四舍五入保留一位或两位小数


本文整理自网络,侵删。

 
delphi 四舍五入保留一位或两位小数写法,后面参数为保留小数点位数

function RoundFloat(f: double; i: integer): double;
var
  s: string;
  ef: Extended;
begin
  if f = 0 then begin
    Result := 0;
    Exit;
  end;
  s := '#.' + StringOfChar('0', i);
  if s = '#.' then s := '#';
  ef := StrToFloat(FloatToStr(f)); //防止浮点运算的误差
  result := StrToFloat(FormatFloat(s, ef));
end;

//调用
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text:=FloatToStr(RoundFloat(StrToFloat(Edit1.Text),2));
end;

相关阅读 >>

Delphi 限制form窗体为固定的大小

Delphi如何在tmemo控件光标当前位置插入字符串

Delphi里实现彩色图片转为黑白图像的功能

Delphi isleapyear、isinleapyear - 是否是闰年

Delphi post数据与对应的接收方式

Delphi的tfilestream 内存流

Delphi 遍历注册表

Delphi android 关闭应用程序对话框询问

Delphi获取uri的查询参数

Delphi xe10 安卓设备信息

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...