SoftBank.Cldr.Money.to_currency-exclamation-mark

You're seeing just the function to_currency-exclamation-mark, go back to SoftBank.Cldr.Money module for more information.
Link to this function

to_currency!(money, currency, rates \\ ExchangeRates.latest_rates())

View Source

Specs

to_currency!(
  Money.t(),
  Money.currency_code(),
  Money.ExchangeRates.t()
  | {:ok, Money.ExchangeRates.t()}
  | {:error, {module(), String.t()}}
) :: Money.t() | no_return()

Convert money from one currency to another and raises on error

Arguments

  • money is any Money.t struct returned by Cldr.Currency.new/2

  • to_currency is a valid currency code into which the money is converted

  • rates is a Map of currency rates where the map key is an upcased atom or string and the value is a Decimal conversion factor. The default is the latest available exchange rates returned from Money.ExchangeRates.latest_rates()

Examples

iex> SoftBank.Cldr.Money.to_currency! Money.new(:USD, 100), :AUD, %{USD: Decimal.new(1), AUD: Decimal.from_float(0.7345)}
#Money<:AUD, 73.4500>

iex> SoftBank.Cldr.Money.to_currency! Money.new("USD", 100), "AUD", %{"USD" => Decimal.new(1), "AUD" => Decimal.from_float(0.7345)}
#Money<:AUD, 73.4500>

SoftBank.Cldr.Money.to_currency! Money.new(:USD, 100), :ZZZ, %{USD: Decimal.new(1), AUD: Decimal.from_float(0.7345)}
** (Cldr.UnknownCurrencyError) Currency :ZZZ is not known