number v1.0.1 Number.Delimit

Provides functions to delimit numbers into strings.

Link to this section Summary

Functions

Formats a number into a string with grouped thousands using delimiter.

Link to this section Functions

Link to this function

number_to_delimited(number, options \\ [])

number_to_delimited(nil, list()) :: nil
number_to_delimited(Number.t(), list()) :: String.t()

Formats a number into a string with grouped thousands using delimiter.

Parameters

  • number - A float or integer to convert.

  • options - A keyword list of options. See the documentation of all available options below for more information.

Options

  • :precision - The number of decimal places to include. Default: 2

  • :delimiter - The character to use to delimit the number by thousands. Default: ","

  • :separator - The character to use to separate the number from the decimal places. Default: "."

Default configuration for these options can be specified in the Number application configuration.

config :number, delimit: [
                  precision: 3,
                  delimiter: ",",
                  separator: "."
                ]

Examples

iex> Number.Delimit.number_to_delimited(nil)
nil

iex> Number.Delimit.number_to_delimited(998.999)
"999.00"

iex> Number.Delimit.number_to_delimited(-234234.234)
"-234,234.23"

iex> Number.Delimit.number_to_delimited("998.999")
"999.00"

iex> Number.Delimit.number_to_delimited("-234234.234")
"-234,234.23"

iex> Number.Delimit.number_to_delimited(12345678)
"12,345,678.00"

iex> Number.Delimit.number_to_delimited(12345678.05)
"12,345,678.05"

iex> Number.Delimit.number_to_delimited(12345678, delimiter: ".")
"12.345.678.00"

iex> Number.Delimit.number_to_delimited(12345678, delimiter: ",")
"12,345,678.00"

iex> Number.Delimit.number_to_delimited(12345678.05, separator: " ")
"12,345,678 05"

iex> Number.Delimit.number_to_delimited(98765432.98, delimiter: " ", separator: ",")
"98 765 432,98"

iex> Number.Delimit.number_to_delimited(Decimal.from_float(9998.2))
"9,998.20"

iex> Number.Delimit.number_to_delimited "123456789555555555555555555555555"
"123,456,789,555,555,555,555,555,555,555,555.00"

iex> Number.Delimit.number_to_delimited Decimal.new("123456789555555555555555555555555")
"123,456,789,555,555,555,555,555,555,555,555.00"