NumberF.CustomFormatter (NumberF v0.1.8)

View Source

Custom 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

number_to_currency(number, opts \\ [])

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"

number_to_delimited(number, opts \\ [])

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"

to_decimal(value)

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>

to_float(value)

Converts a value to a float.

Examples

iex> NumberF.CustomFormatter.to_float("123.45")
123.45

iex> NumberF.CustomFormatter.to_float(123)
123.0