NumberF.Currencies (NumberF v0.1.6)

View Source

Functions 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

convert(amount, from_currency, to_currency, exchange_rates, base_currency \\ "USD")

Converts an amount from one currency to another using exchange rates.

Parameters

  • amount: The amount to convert
  • from_currency: Source currency code
  • to_currency: Target currency code
  • exchange_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

currency_data()

Returns a map of currency information with ISO codes, symbols, and formatting details.

format(number, currency_code, options \\ [])

Formats a number according to the currency's formatting rules.

Parameters

  • number: The number to format
  • currency_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"

get_currency(currency_code)

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: "."
}

parse(currency_string, currency_code \\ nil)

Parses a currency string into its numeric value.

Parameters

  • currency_string: The currency string to parse
  • currency_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