Money.from_integer

You're seeing just the function from_integer, go back to Money module for more information.
Link to this function

from_integer(amount, currency, options \\ [])

View Source

Specs

from_integer(integer(), currency_code(), Keyword.t()) ::
  t() | {:error, module(), String.t()}

Convert an integer representation of money into a Money struct.

This is the inverse operation of Money.to_integer_exp/1. Note that the ISO definition of currency digits (subunit) is always used. This is, in some cases like the Colombian Peso (COP) different to the CLDR definition.

Options

  • integer is an integer representation of a mooney item including any decimal digits. ie. 20000 would interpreted to mean $200.00

  • currency is the currency code for the integer. The assumed decimal places is derived from the currency code.

  • options is a keyword list of options passed to Money.new/3

Returns

  • A t:Money struct or

  • {:error, {Cldr.UnknownCurrencyError, message}}

Examples

iex> Money.from_integer(20000, :USD)
#Money<:USD, 200.00>

iex> Money.from_integer(200, :JPY)
#Money<:JPY, 200>

iex> Money.from_integer(20012, :USD)
#Money<:USD, 200.12>

iex> Money.from_integer(20012, :COP)
#Money<:COP, 200.12>