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 SourceSpecs
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 anyMoney.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> 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