number v1.0.1 Number.Human

Provides functions for converting numbers into more human readable strings.

Link to this section Summary

Functions

Formats and labels a number with the appropriate English word.

Adds ordinal suffix (st, nd, rd or th) for the number

Link to this section Functions

Link to this function

number_to_human(number, options \\ [])

Formats and labels a number with the appropriate English word.

Examples

iex> Number.Human.number_to_human(123)
"123.00"

iex> Number.Human.number_to_human(1234)
"1.23 Thousand"

iex> Number.Human.number_to_human(999001)
"999.00 Thousand"

iex> Number.Human.number_to_human(1234567)
"1.23 Million"

iex> Number.Human.number_to_human(1234567890)
"1.23 Billion"

iex> Number.Human.number_to_human(1234567890123)
"1.23 Trillion"

iex> Number.Human.number_to_human(1234567890123456)
"1.23 Quadrillion"

iex> Number.Human.number_to_human(1234567890123456789)
"1,234.57 Quadrillion"

iex> Number.Human.number_to_human(Decimal.new("5000.0"))
"5.00 Thousand"

iex> Number.Human.number_to_human('charlist')
** (ArgumentError) number must be a float, integer or implement [`Number.Conversion`](Number.Conversion.html) protocol, was 'charlist'
Link to this function

number_to_ordinal(number)

Adds ordinal suffix (st, nd, rd or th) for the number

Examples

iex> Number.Human.number_to_ordinal(3)
"3rd"

iex> Number.Human.number_to_ordinal(1)
"1st"

iex> Number.Human.number_to_ordinal(46)
"46th"

iex> Number.Human.number_to_ordinal(442)
"442nd"

iex> Number.Human.number_to_ordinal(4001)
"4001st"