Float
Functions for working with floating point numbers.
Summary
| ceil(num) | Round a float to the largest integer greater than or equal to |
| floor(num) | Round a float to the largest integer less than or equal to |
| parse(binary) | Parses a binary into a float |
| round(number, precision) | Rounds a floating point value to an arbitrary number of fractional digits (between 0 and 15) |
Functions
Specs:
- ceil(float | integer) :: integer
Round a float to the largest integer greater than or equal to num
Examples
iex> Float.ceil(34)
34
iex> Float.ceil(34.25)
35
iex> Float.ceil(-56.5)
-56
Specs:
- floor(float | integer) :: integer
Round a float to the largest integer less than or equal to num
Examples
iex> Float.floor(34)
34
iex> Float.floor(34.25)
34
iex> Float.floor(-56.5)
-57
Specs:
- parse(binary) :: {float, binary} | :error
Parses a binary into a float.
If successful, returns a tuple of the form { float, remainder_of_binary }.
Otherwise :error.
Examples
iex> Float.parse("34")
{34.0,""}
iex> Float.parse("34.25")
{34.25,""}
iex> Float.parse("56.5xyz")
{56.5,"xyz"}
iex> Float.parse("pi")
:error
Specs:
- round(float, integer) :: float
Rounds a floating point value to an arbitrary number of fractional digits (between 0 and 15).
Examples
iex> Float.round(5.5674, 3)
5.567
iex> Float.round(5.5675, 3)
5.568
iex> Float.round(-5.5674, 3)
-5.567
iex> Float.round(-5.5675, 3)
-5.568