delphi - 如何将正 float 向上舍入到下一个整数?

标签 delphi delphi-2010

我需要将正 float 向上舍入到最接近的整数。

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 

即始终向上舍入。

最佳答案

使用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()< 来编写满足您需求的函数。/

关于delphi - 如何将正 float 向上舍入到下一个整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25972678/

相关文章:

mysql - 基于数据库查询调用TEdit对象

德尔福2010 : whatever happened to TRTTIConstructor?

delphi - 传递对 TObjectDictionary<TKey, TValue>.TValueEnumerator 的引用

delphi - Delphi 2010 准备好用于生产了吗?

delphi - 小型命令行脚本编写器(如 Autocad 命令)单行编辑器

delphi - TWebBrowser 的 HTML 源代码 - 如何检测流编码?

delphi - 调整 TStringList 大小的更好方法?

android - 使用delphi使用外部图库打开图像

delphi - 如何将 Variant 转换为 TADOConnection.ConnectionObject?

delphi - 如何在 DataSnap 方法中返回记录