The Float.round/2arrow-up-right function allows you to round floating point numbers. The result is another floating point number.
Float.round/2
> Float.round(1.5) 2.0 > Float.round(1.3) 1.0
If, instead, you always want an integer as the result of rounding, you can use Kernel's version of a rounding function:
Kernel
> Kernel.round(1.5) 2 > Kernel.round(1.3) 1
The Kernel.round/1arrow-up-right function accepts both integers and floats, and always returns an integer. Additionally, it can be used in guard tests.
Kernel.round/1
Last updated 4 years ago