Number.Delimit
Provides functions to delimit numbers into strings.
Summary↑
number_to_delimited(number, options \\ []) | Formats a number into a string with grouped thousands using |
Functions
Specs:
- number_to_delimited(number, list) :: String.t
Formats a number into a string with grouped thousands using delimiter
.
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 settings for these options can be specified in the Number
application configuration.
config :number, delimiter: [
precision: 3,
delimiter: ",",
separator: "."
]
Examples
iex> Number.Delimit.number_to_delimited(nil)
nil
iex> Number.Delimit.number_to_delimited(-234234.234)
"-234,234.23"
iex> Number.Delimit.number_to_delimited(12345678)
"12,345,678"
iex> Number.Delimit.number_to_delimited(12345678.05)
"12,345,678.05"
iex> Number.Delimit.number_to_delimited(12345678, delimiter: ".")
"12.345.678"
iex> Number.Delimit.number_to_delimited(12345678, delimiter: ",")
"12,345,678"
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"