Money.to_currency-exclamation-mark
You're seeing just the function
to_currency-exclamation-mark
, go back to Money module for more information.
Link to this function
to_currency!(money, to_currency, rates \\ Money.ExchangeRates.latest_rates())
View SourceSpecs
to_currency!( t(), currency_code(), Money.ExchangeRates.t() | {:ok, Money.ExchangeRates.t()} | {:error, {module(), String.t()}} ) :: t() | no_return()
Convert money
from one currency to another and raises on error
Arguments
money
is anyt:Money.t()
struct returned byCldr.Currency.new/2
to_currency
is a valid currency code into which themoney
is convertedrates
is aMap
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 fromMoney.ExchangeRates.latest_rates()
Examples
iex> Money.to_currency! Money.new(:USD, 100), :AUD,
...> %{USD: Decimal.new(1), AUD: Decimal.from_float(0.7345)}
#Money<:AUD, 73.4500>
iex> Money.to_currency! Money.new("USD", 100), "AUD",
...> %{"USD" => Decimal.new(1), "AUD" => Decimal.from_float(0.7345)}
#Money<:AUD, 73.4500>
=> 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