View Source BetterNumber.Human (better_number v1.0.1)

Provides functions for converting numbers into more human readable strings.

Summary

Functions

Formats and labels a number with the appropriate English word.

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

Functions

Link to this function

number_to_human(number, options \\ %{})

View Source
@spec number_to_human(BetterNumber.t(), map() | Keyword.t()) :: String.t()

Formats and labels a number with the appropriate English word.

Options

  • :units - List of units to convert to

Examples

iex> number_to_human(123)
"123.00"
iex> number_to_human(1234)
"1.23 Thousand"
iex> number_to_human(999001)
"999.00 Thousand"
iex> number_to_human(1234567)
"1.23 Million"
iex> number_to_human(1234567890)
"1.23 Billion"
iex> number_to_human(1234567890123)
"1.23 Trillion"
iex> number_to_human(1234567890123456)
"1.23 Quadrillion"
iex> number_to_human(1234567890123456789)
"1,234.57 Quadrillion"
iex> number_to_human(Decimal.new("5000.0"))
"5.00 Thousand"
iex> number_to_human(123, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"123.00 B"
iex> number_to_human(1234, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"1.23 KB"
iex> number_to_human(999001, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"999.00 KB"
iex> number_to_human(1234567, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"1.23 MB"
iex> number_to_human(1234567890, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"1.23 GB"
iex> number_to_human(1234567890123, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"1.23 TB"
iex> number_to_human(1234567890123456, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"1.23 PB"
iex> number_to_human(1234567890123456789, units: ["B", "KB", "MB", "GB", "TB", "PB"])
"1,234.57 PB"
Link to this function

number_to_ordinal(number)

View Source

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

Examples

iex> BetterNumber.Human.number_to_ordinal(3)
"3rd"
iex> BetterNumber.Human.number_to_ordinal(1)
"1st"
iex> BetterNumber.Human.number_to_ordinal(46)
"46th"
iex> BetterNumber.Human.number_to_ordinal(442)
"442nd"
iex> BetterNumber.Human.number_to_ordinal(4001)
"4001st"