View Source Hologram.Commons.IntegerUtils (hologram v0.2.0)

Summary

Functions

Counts the number of digits in the given integer.

Returns the ordinal number (number with suffix "st", "nd", "rd", or "th") for a given integer.

Parses a text representation of an integer.

Functions

count_digits(integer)

@spec count_digits(integer()) :: non_neg_integer()

Counts the number of digits in the given integer.

Examples

iex> count_digits(123)
3

iex> count_digits(0)
1

iex> count_digits(-123)
3

ordinal(int)

@spec ordinal(integer()) :: String.t()

Returns the ordinal number (number with suffix "st", "nd", "rd", or "th") for a given integer.

Examples

iex> ordinal(1)
"1st"

iex> ordinal(42)
"42nd"

iex> ordinal(11)
"11th"

parse!(binary, base \\ 10)

@spec parse!(String.t(), integer()) :: integer()

Parses a text representation of an integer.

Raises an error if the text representation can't be parsed, or if the base is less than 2 or more than 36, or if only part of the text representation can be parsed.