PTAX.Money (ptax v1.1.0)
Defines a Money
structure for working with currencies.
Link to this section Summary
Functions
Exchange from a currency to another given the rate.
Create a new Money
given the amount and currency.
Link to this section Types
Link to this type
amount()
@type amount() :: Decimal.t()
Link to this type
currency()
@type currency() :: atom()
Link to this type
pair()
@type pair() :: PTAX.Money.Pair.t()
Link to this section Functions
Link to this function
exchange(money, pair)
Exchange from a currency to another given the rate.
examples
Examples:
iex> PTAX.Money.exchange(PTAX.Money.new(10, :USD), PTAX.Money.Pair.new(5, "5.5", :USD, :BRL))
PTAX.Money.new(50, :BRL)
iex> PTAX.Money.exchange(PTAX.Money.new(1, :USD), PTAX.Money.Pair.new("1.5", 2, :GBP, :USD))
PTAX.Money.new("0.5", :GBP)
iex> PTAX.Money.exchange(PTAX.Money.new(115, :JPY), PTAX.Money.Pair.new("114.5", 115, :USD, :JPY))
PTAX.Money.new(1, :USD)
iex> PTAX.Money.exchange(PTAX.Money.new(1, :USD), PTAX.Money.Pair.new("114.5", 115, :USD, :JPY))
PTAX.Money.new("114.5", :JPY)
Link to this function
new(amount, currency \\ :BRL)
Create a new Money
given the amount and currency.
examples
Examples:
iex> PTAX.Money.new(10)
%PTAX.Money{amount: PTAX.Money.to_amount(10), currency: :BRL}
iex> PTAX.Money.new("12.75", :USD)
%PTAX.Money{amount: PTAX.Money.to_amount("12.75"), currency: :USD}
iex> PTAX.Money.new(123, :GBP)
%PTAX.Money{amount: PTAX.Money.to_amount(123), currency: :GBP}
Link to this function