我需要将正 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/