NumberF.CustomFormatter (NumberF v0.1.6)
View SourceCustom implementations for number formatting functions. Replaces functionality from the 'number' dependency.
Summary
Functions
Formats a number as currency with specified unit and precision.
Formats a number with delimiters for thousands and decimal separator.
Converts a value to a Decimal.
Converts a value to a float.
Functions
Formats a number as currency with specified unit and precision.
Examples
iex> NumberF.CustomFormatter.number_to_currency(1234.56, unit: "USD", precision: 2)
"USD 1,234.56"
iex> NumberF.CustomFormatter.number_to_currency("1234.56", unit: "USD", precision: 2)
"USD 1,234.56"
Formats a number with delimiters for thousands and decimal separator.
Examples
iex> NumberF.CustomFormatter.number_to_delimited(1234567.89, delimiter: ",", separator: ".", precision: 2)
"1,234,567.89"
iex> NumberF.CustomFormatter.number_to_delimited("1234567.89", delimiter: ",", separator: ".", precision: 2)
"1,234,567.89"
Converts a value to a Decimal.
Examples
iex> NumberF.CustomFormatter.to_decimal("123.45")
#Decimal<123.45>
iex> NumberF.CustomFormatter.to_decimal(123)
#Decimal<123>
Converts a value to a float.
Examples
iex> NumberF.CustomFormatter.to_float("123.45")
123.45
iex> NumberF.CustomFormatter.to_float(123)
123.0