加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 如何将正浮点数向上舍入下一个整数?

发布时间:2020-12-15 09:49:34 所属栏目:大数据 来源:网络整理
导读:我需要将正向浮动向上舍入到最接近的整数. examples;1.0 rounds up to 1 2.1 rounds up to 33.5 rounds up to 44.9 rounds up to 5 即总是围捕. 解决方法 使用Math单元中的 Ceil 功能.从文档: Rounds variables up toward positive infinity. Call Ceil (as
我需要将正向浮动向上舍入到最接近的整数.

examples;

1.0 rounds up to 1    
2.1 rounds up to 3
3.5 rounds up to 4
4.9 rounds up to 5

即总是围捕.

解决方法

使用Math单元中的 Ceil功能.从文档:

Rounds variables up toward positive infinity.

Call Ceil (as in ceiling) to obtain the lowest integer greater than or
equal to X. The absolute value of X must be less than MaxInt. For
example:

  • Ceil(-2.8) = -2
  • Ceil(2.8) = 3
  • Ceil(-1.0) = -1

我无法判断Ceil的行为是否符合您对负输入值的期望,因为您没有指定在那里做什么.但是,如果Ceil不符合您的期望,通过组合Abs()和Ceil()来编写满足您需求的函数是很容易的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读