SoftBank.Cldr.Money.new
You're seeing just the function
new
, go back to SoftBank.Cldr.Money module for more information.
Specs
new( Money.amount() | Money.currency_code(), Money.amount() | Money.currency_code(), Keyword.t() ) :: Money.t() | {:error, {module(), String.t()}}
Returns a %:'Elixir.Money'{} struct from a currency code and a currency amount or
an error tuple of the form {:error, {exception, message}}
.
Arguments
currency_code
is an ISO4217 three-character upcased binary or atomamount
is an integer, string or Decimal
Options
:locale
is any known locale. The locale is used to normalize any
binary (String) amounts to a form that can be consumed by Decimal.new/1
.
This consists of removing any localised grouping characters and replacing
the localised decimal separator with a ".".
Note that the currency_code
and amount
arguments can be supplied in
either order,
Examples
iex> SoftBank.Cldr.Money.new(:USD, 100)
#Money<:USD, 100>
iex> SoftBank.Cldr.Money.new(100, :USD)
#Money<:USD, 100>
iex> SoftBank.Cldr.Money.new("USD", 100)
#Money<:USD, 100>
iex> SoftBank.Cldr.Money.new("thb", 500)
#Money<:THB, 500>
iex> SoftBank.Cldr.Money.new("EUR", Decimal.new(100))
#Money<:EUR, 100>
iex> SoftBank.Cldr.Money.new(:EUR, "100.30")
#Money<:EUR, 100.30>
iex> SoftBank.Cldr.Money.new(:XYZZ, 100)
{:error, {Money.UnknownCurrencyError, "The currency :XYZZ is invalid"}}
iex> SoftBank.Cldr.Money.new("1.000,99", :EUR, locale: "de")
#Money<:EUR, 1000.99>
iex> SoftBank.Cldr.Money.new 123.445, :USD
{:error,
{Money.InvalidAmountError,
"Float amounts are not supported in new/2 due to potenial " <>
"rounding and precision issues. If absolutely required, " <>
"use Money.from_float/2"}}