NumberF.Currencies (NumberF v0.1.5)
View SourceFunctions and data for handling currency-specific operations and information.
Summary
Functions
Converts an amount from one currency to another using exchange rates.
Returns a map of currency information with ISO codes, symbols, and formatting details.
Formats a number according to the currency's formatting rules.
Gets currency details for a specific currency code.
Parses a currency string into its numeric value.
Functions
Converts an amount from one currency to another using exchange rates.
Parameters
amount
: The amount to convertfrom_currency
: Source currency codeto_currency
: Target currency codeexchange_rates
: Map of exchange rates (relative to a base currency)base_currency
: The base currency for the exchange rates (default: "USD")
Examples
iex> exchange_rates = %{"USD" => 1.0, "EUR" => 0.85, "GBP" => 0.75}
iex> NumberF.Currencies.convert(100, "USD", "EUR", exchange_rates)
85.0
Returns a map of currency information with ISO codes, symbols, and formatting details.
Formats a number according to the currency's formatting rules.
Parameters
number
: The number to formatcurrency_code
: ISO currency code (e.g., "USD", "EUR")options
: Additional formatting options (overrides defaults)
Examples
iex> NumberF.Currencies.format(1234.56, "USD")
"$1,234.56"
iex> NumberF.Currencies.format(1234.56, "EUR")
"1.234,56 €"
iex> NumberF.Currencies.format(1234.56, "USD", symbol: false)
"1,234.56"
Gets currency details for a specific currency code.
Parameters
currency_code
: ISO currency code (e.g., "USD", "EUR")
Examples
iex> NumberF.Currencies.get_currency("USD")
%{
name: "US Dollar",
symbol: "$",
symbol_first: true,
symbol_space: false,
decimal_places: 2,
thousands_separator: ",",
decimal_separator: "."
}
Parses a currency string into its numeric value.
Parameters
currency_string
: The currency string to parsecurrency_code
: ISO currency code for formatting reference (optional)
Examples
iex> NumberF.Currencies.parse("$1,234.56")
1234.56
iex> NumberF.Currencies.parse("1.234,56 €", "EUR")
1234.56