Packages

Money functions for operations on and localization of a money data type with support for ISO 4217 currencies and ISO 24165 digial tokens (crypto currencies).

Current section

Files

Jump to
ex_money lib money sigil.ex
Raw

lib/money/sigil.ex

defmodule Money.Sigil do
@doc ~S"""
Implements the sigil `~M` for Money
The lower case `~m` variant does not exist as interpolation and excape
characters are not useful for Money sigils.
## Example
import Money.Sigil
iex> ~M[1000]usd
#Money<:USD, 1000>
"""
def sigil_M(amount, [_, _, _] = currency) do
Money.new(to_decimal(amount), atomize(currency))
end
defp to_decimal(string) do
string
|> String.replace("_", "")
|> Decimal.new
end
defp atomize(currency) do
currency
|> List.to_string
|> String.upcase
|> String.to_existing_atom
end
end