A.Integer (Aja v0.4.3) View Source

Some extra helper functions for working with integers, that are not in the core Integer module.

Link to this section Summary

Functions

Format integers for humans, with thousand separators.

Returns both the result of div/2 and rem/2 at once.

Link to this section Functions

Link to this function

decimal_format(integer, opts \\ [])

View Source

Format integers for humans, with thousand separators.

Examples

iex> A.Integer.decimal_format(1_234_567)
"1,234,567"
iex> A.Integer.decimal_format(-123)
"-123"
iex> A.Integer.decimal_format(-1_234, separator: ?_)
"-1_234"
Link to this function

div_rem(dividend, divisor)

View Source

Specs

div_rem(integer(), pos_integer() | neg_integer()) :: {integer(), integer()}

Returns both the result of div/2 and rem/2 at once.

Examples

iex> A.Integer.div_rem(7, 3)
{2, 1}
iex> A.Integer.div_rem(-99, 2)
{-49, -1}
iex> A.Integer.div_rem(100, 0)
** (ArithmeticError) bad argument in arithmetic expression