Skip to content

Numeric

abs(value)

Return the abs of the given number.

ceil(value)

Return the ceil of the given number.

floor(value)

Return the floor of the given number.

max(a, b)

Return the max of the given numbers.

min(a, b)

Return the min of the given numbers.

modulo(a, b)

Return the modulo of the given numbers.

number(value)

Converts most values to their numeric counterpart. Returns nil when conversion fails.

parse_float(string, opts \\ [])

Attempt to parse a string to a float.

Options:

  • :allow_trailing: Whether or not to allow trailing non-integer text.

Examples:

iex> parse_float("1")
1.0
iex> parse_float("1a")
nil
iex> parse_float("1a", allow_trailing: true)
1.0
iex> parse_float("bla")
nil
iex> parse_float("43.3")
43.3
iex> parse_float("43.2hello")
nil
iex> parse_float("43.2hello", allow_trailing: true)
43.2

parse_int(string, opts \\ [])

Attempt to parse a string to an integer.

Options:

  • :radix: The radix to use when parsing. Defaults to 10.
  • :allow_trailing: Whether or not to allow trailing non-integer text.

Examples:

iex> parse_int("1")
1
iex> parse_int("1a")
nil
iex> parse_int("1a", allow_trailing: true)
1
iex> parse_int("bla")
nil
iex> parse_int("1011", radix: 2)
11

round(value)

Return the round of the given number.