MyApp.Cldr.Currency.new

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

new(currency, options \\ [])

View Source

Specs

new(Cldr.Currency.code(), map() | Keyword.t()) ::
  {:ok, Cldr.Currency.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 currency. 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_rounding_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> MyApp.Cldr.Currency.new(:XAA, name: "Custom Name", digits: 0)
  {:ok,
   %Cldr.Currency{
     alt_code: :XAA,
     cash_digits: 0,
     cash_rounding: nil,
     code: :XAA,
     count: %{other: "Custom Name"},
     digits: 0,
     from: nil,
     iso_digits: 0,
     name: "Custom Name",
     narrow_symbol: nil,
     rounding: 0,
     symbol: "XAA",
     tender: false,
     to: nil
   }}

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

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