How to combine a positive number followed by an integer?

I need to round the positive float up to the nearest integer.

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 

i.e. always rounded.

+5
source share
1 answer

Use the Ceil function from the Math block. From the documentation:

Rounds move towards positive infinity.

Call Ceil (as in the ceiling) to get the smallest integer greater than or greater than 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

I can’t say if Ceil behavior is in Ceil your expectations regarding negative input values ​​because you didn’t specify what to do there. However, if Ceil does not meet your expectations, just write a function to meet your needs by combining Abs() and Ceil()

+13
source

Source: https://habr.com/ru/post/1203129/


All Articles