捐赠 | 广告 | 注册 | 发布 | 上传 | 关于我们    
  沪ICP备05001939号 DELPHI盒子 | 盒子论坛 | 盒子文章 | 盒子问答悬赏 | 最新更新 | 论坛检索 | 下载中心 | 高级搜索    
  精品专区 | 繁體中文 | 奖励公告栏 | 直通车账号登陆 | 关闭GOOGLE广告 | 临时留言    
盒子资源分类
全部展开 - 全部合拢
将数字四舍五入保留两位小数
关键字:四舍五入 SSWR 字符串 数字 小数
来 自:原创
平 台:Win9x,Win2k/NT,WinXP 下载所需:0 火柴
深浅度:初级 完成时间:2004/7/14
发布者:hongfeng 发布时间:2004/7/14
编辑器:DELPHI7 语  种:简体中文
分 类:科学 下载浏览:282/13918
加入到我的收藏
下载错误报错
登陆以后才能下载
 用户名:
 密 码:
自动登陆(30天有效)
无图片
function SSWR(s: real): real;
var
  r1, r2: real;
  s1, s2: string;
begin
  r1 := int(s);
  r2 := frac(s);
  s1 := copy(floattostr(r1), 1, length(floattostr(r1)));
  if length(floattostr(r2)) >= 5 then
  begin
    if strtoint(copy((floattostr(r2)), 5, 1)) >= 5 then
      if strtoint(copy((floattostr(r2)), 4, 1)) = 9 then
        if strtoint(copy((floattostr(r2)), 3, 1)) = 9 then
        begin
          s1 := inttostr(strtoint(s1) + 1);
          s2 := ';
        end
        else
          S2 := inttostr(strtoint(copy((floattostr(r2)), 3, 1)) + 1)
      else if copy((floattostr(r2)), 3, 1) = '0' then
        S2 := '0' + inttostr(strtoint(copy(floattostr(r2), 3, 2)) + 1)
      else s2 := inttostr(strtoint(copy(floattostr(r2), 3, 2)) + 1)
    else s2 := copy(floattostr(r2), 3, 2);
  end
  else s2 := copy(floattostr(r2), 3, 2);
  result := strtofloat(s1 + '.' + s2);
end;
//搞一个数字处理的程序,要用到四舍五入,将此函数奉上,供大家讨论。
Google
 
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们
龙脉加密锁 15元起 Grid++Report 报表 申请支付@网
 相关文章
没有相关文章
相关评论
共有评论16条 当前显示最后6条评论
wr960204 2004/8/18 18:03:46
uses
  Math;
SimpleRoundTo函数就是四舍五入
blazingfire 2004/8/18 19:43:02
这几行代码实在不敢公为。要效率没有效率
其实要达到这个功能很简单就可以实现的
qian8233 2004/8/19 18:34:15
由于对系统函数的了解太少,出现这种情况是可以理解的;
对于delphi7中的roundto函数帮助:“RoundTo(1234567, 3)=1234000”是完全错误的,而且实际的运行结果跟我们小学时对四舍五入的理解完全一致:1235000。
web700 2005/1/18 11:39:36
function intdata(d:double):double;
begin
  result:=int((d+0.5)*100/100);
end;
tinysoft 2005/2/25 21:09:13
看了大家的方法,我还是喜欢用Format函数!
gz818 2006/1/20 17:43:52
delphi7 下如何四舍六入五单双?
我要发表评论 查看全部评论
 
  DELPHI盒子版权所有 1999-2023 V4.01 粤ICP备10103342号-1 更新RSS列表