currency v1.0.0 Currency
Currency
represents a monetary value, stored in its smallest unit possible
in a given currency, i.e., cents.
See Currency.Ecto
for a custom type implementation that can be used in a
schema.
In order to use the ~M
sigil, import the module:
import Currency
Example
iex> Currency.new("25.00 USD")
~M"25.00 USD"
iex> ~M"25.00 USD".currency
"USD"
iex> ~M"25.01 USD".units
#Decimal<2501>
iex> Currency.add(~M"10 USD", ~M"20 USD")
~M"30.00 USD"
iex> Kernel.to_string(~M"-10.50 USD")
"-10.50 USD"
iex> ~M"12.348 USD"
~M"12.35 USD"
# For cases which have more than 2 decimal places of precision
iex> ~M"1500.23 CLF"
~M"1500.2300 CLF"
# For cases which have 0 decimals of precision
iex> ~M"500.1 XOF"
~M"500 XOF"
Link to this section Summary
Link to this section Functions
Link to this function
add(currency1, currency2)
Link to this function
new(str)
Link to this function
pad_or_round(minor_units, precision)
Link to this function
pad_zeros(minor_units, precision)
Link to this function
parse(str)
Link to this function
sigil_M(str, opts)
Link to this function
subtract(currency1, currency2)
Link to this function