Monetized v0.1.0 Monetized.Math
This modules defines mathematical operations using money.
All functions in this module take either money struct as
parameters from which the currency is copied or it will
convert the given values into a money struct using
Monetized.Money.make/1
which in turn will use the default
currency.
Summary
Functions
Specs
add(Monetized.Money.money | String.t | integer | float, Monetized.Money.money | String.t | integer | float) :: Monetized.Money.money
Adds money to money returning a money struct with the result.
Examples
iex> payment_one = Monetized.Money.make(10, [currency: "GBP"])
...> payment_two = Monetized.Money.make(20.50, [currency: "GBP"])
...> result = Monetized.Math.add(payment_one, payment_two)
...> Monetized.Money.to_string(result, [show_currency: true])
"£ 30.50"
iex> result = Monetized.Math.add(100.50, 200)
...> Monetized.Money.to_string(result, [show_currency: true])
"$ 300.50"
Specs
sub(Monetized.Money.money | String.t | integer | float, Monetized.Money.money | String.t | integer | float) :: Monetized.Money.money
Substracts money from money returning a money struct with the result.
Examples
iex> payment_one = Monetized.Money.make(50)
...> payment_two = Monetized.Money.make(51)
...> Monetized.Math.sub(payment_one, payment_two)
%Monetized.Money{currency: "USD", units: -100}
iex> payment_one = Monetized.Money.make(2000)
...> payment_two = Monetized.Money.make(150.25)
...> result = Monetized.Math.sub(payment_one, payment_two)
...> Monetized.Money.to_string(result, [show_currency: true])
"$ 1,849.75"
iex> result = Monetized.Math.sub(100.50, 200)
...> Monetized.Money.to_string(result, [show_currency: true])
"$ -99.50"