Float.ceil
You're seeing just the function
ceil
, go back to Float module for more information.
Specs
ceil(float(), precision_range()) :: float()
Rounds a float to the smallest integer greater than or equal to num
.
ceil/2
also accepts a precision to round a floating-point value down
to an arbitrary number of fractional digits (between 0 and 15).
The operation is performed on the binary floating point, without a conversion to decimal.
The behaviour of ceil/2
for floats can be surprising. For example:
iex> Float.ceil(-12.52, 2)
-12.51
One may have expected it to ceil to -12.52. This is not a bug. Most decimal fractions cannot be represented as a binary floating point and therefore the number above is internally represented as -12.51999999, which explains the behaviour above.
This function always returns floats. Kernel.trunc/1
may be used instead to
truncate the result to an integer afterwards.
Examples
iex> Float.ceil(34.25)
35.0
iex> Float.ceil(-56.5)
-56.0
iex> Float.ceil(34.251, 2)
34.26