Cldr.Currency.new

You're seeing just the function new, go back to Cldr.Currency module for more information.
Link to this function

new(currency, options \\ [])

View Source

Specs

new(binary() | atom(), map() | list()) ::
  {:ok, t()} | {:error, {module(), String.t()}}

Returns a Currency struct created from the arguments.

Arguments

  • currency is a private use currency code in a format defined by ISO4217 which is X followed by two alphanumeric characters.

  • options is a map of options representing the optional elements of the Cldr.Currency.t struct.

Options

  • :name is the name of the currenct. Required.
  • :digits is the precision of the currency. Required.
  • :symbol is the currency symbol. Optional.
  • :narrow_symbol is an alternative narrow symbol. Optional.
  • :round_nearest is the rounding precision such as 0.05. Optional.
  • :alt_code is an alternative currency code for application use.
  • :cash_digits is the precision of the currency when used as cash. Optional.
  • :cash_round_nearest is the rounding precision when used as cash such as 0.05. Optional.

Returns

  • {:ok, Cldr.Currency.t} or

  • {:error, {exception, message}}

Example

iex> Cldr.Currency.new(:XAA, name: "XAA currency", digits: 0)
{:ok,
 %Cldr.Currency{
   alt_code: :XAA,
   cash_digits: 0,
   cash_rounding: nil,
   code: :XAA,
   count: %{other: "XAA currency"},
   digits: 0,
   from: nil,
   iso_digits: 0,
   name: "XAA currency",
   narrow_symbol: nil,
   rounding: 0,
   symbol: "XAA",
   tender: false,
   to: nil
 }}

iex> Cldr.Currency.new(:XBC)
{:error, {Cldr.CurrencyAlreadyDefined, "Currency :XBC is already defined."}}

iex> MyApp.Cldr.Currency.new(:XAA, name: "Private Use Name")
{:error, "Required options are missing. Required options are [:name, :digits]"}

iex> Cldr.Currency.new(:ZAA, name: "Invalid Private Use Name", digits: 0)
{:error, {Cldr.UnknownCurrencyError, "The currency :ZAA is invalid"}}