Dinheiro v0.1.5 Moeda View Source

Documentation for Moeda.

Link to this section Summary

Types

t()

Type that represents Moeda struct with:

:nome as String.t that represents the name of the currency.
:simbolo as String.t that represents symbol of the currency.
:codigo as String.t that represents the ISO 4217 code.
:codigo_iso as integer that represents the country code.
:expoente as integer that represents the exponent of the currency

Functions

Return a map from an atom or string that represents an ISO 4217 code

Return an atom from a value that represents an ISO 4217 code

Return a multiplication factor from an ISO 4217 code

Return a formated string from a ISO 4217 code and a float value

Link to this section Types

Link to this type t() View Source
t() :: %Moeda{
  codigo: String.t(),
  codigo_iso: integer(),
  expoente: integer(),
  nome: String.t(),
  simbolo: String.t()
}
Type that represents [`Moeda`](Moeda.html#content) struct with:
:nome as String.t that represents the name of the currency.
:simbolo as String.t that represents symbol of the currency.
:codigo as String.t that represents the ISO 4217 code.
:codigo_iso as integer that represents the country code.
:expoente as integer that represents the exponent of the currency.

Link to this section Functions

Link to this function find(codigo) View Source
find(String.t() | atom()) :: map() | nil

Return a map from an atom or string that represents an ISO 4217 code.

Examples

iex> Moeda.find(:BRL)
%{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> Moeda.find("BRL")
%{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> Moeda.find("")
nil

Its function ignore case sensitive.

Examples

iex> Moeda.find(:brl)
%{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> Moeda.find("brl")
%{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}

Is possible to work with no official ISO currency code adding it in the system Mix config.

Examples

iex> Moeda.find(:XBT)
nil
iex> moedas = %{ XBT: %{nome: "Bitcoin", simbolo: '฿', codigo: "XBT", codigo_iso: 0, expoente: 8} }
iex> Application.put_env(:ex_dinheiro, :unofficial_currencies, moedas)
iex> Moeda.find("xbt")
%{nome: "Bitcoin", simbolo: '฿', codigo: "XBT", codigo_iso: 0, expoente: 8}

Is possible to override some official ISO currency code adding it in the system Mix config.

Examples

iex> Moeda.find(:BRL)
%{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> moedas = %{ BRL: %{nome: "Moeda do Brasil", simbolo: 'BR$', codigo: "BRL", codigo_iso: 986, expoente: 4}, USD: %{nome: "Moeda do EUA", simbolo: 'US$', codigo: "USD", codigo_iso: 986, expoente: 3} }
iex> Application.put_env(:ex_dinheiro, :unofficial_currencies, moedas)
iex> Moeda.find(:BRL)
%{nome: "Moeda do Brasil", simbolo: 'BR$', codigo: "BRL", codigo_iso: 986, expoente: 4}
iex> Moeda.find(:USD)
%{nome: "Moeda do EUA", simbolo: 'US$', codigo: "USD", codigo_iso: 986, expoente: 3}
Link to this function get_atom(codigo) View Source
get_atom(String.t() | atom()) :: atom() | nil

Return an atom from a value that represents an ISO 4217 code.

Examples

iex> Moeda.get_atom(:BRL)
:BRL
iex> Moeda.get_atom("BRL")
:BRL
iex> Moeda.get_atom("")
nil

Its function ignore case sensitive.

Examples

iex> Moeda.get_atom(:brl)
:BRL
iex> Moeda.get_atom("brl")
:BRL
Link to this function get_factor(codigo) View Source
get_factor(String.t() | atom()) :: float() | nil

Return a multiplication factor from an ISO 4217 code.

Examples

iex> Moeda.get_factor(:BRL)
100.0
iex> Moeda.get_factor("BRL")
100.0
iex> Moeda.get_factor("")
nil

Its function ignore case sensitive.

Examples

iex> Moeda.get_factor(:brl)
100.0
iex> Moeda.get_factor("brl")
100.0
Link to this function to_string(moeda, valor, opts \\ []) View Source
to_string(String.t() | atom(), float(), Keywords.t()) :: String.t()

Return a formated string from a ISO 4217 code and a float value.

Examples

iex> Moeda.to_string(:BRL, 100.0)
"R$ 100,00"
iex> Moeda.to_string("BRL", 1000.5)
"R$ 1.000,50"
iex> Moeda.to_string(:BRL, -1.0)
"R$ -1,00"

Its function ignore case sensitive.

Examples

iex> Moeda.to_string(:bRl, 100.0)
"R$ 100,00"
iex> Moeda.to_string("BrL", 1000.5)
"R$ 1.000,50"

Using options-style parameters you can change the behavior of the function.

  • thousand_separator - default ".", set the thousand separator.
  • decimal_separator - default ",", set the decimal separator.
  • display_currency_symbol - default true, put to false to hide de currency symbol.
  • display_currency_code - default false, put to true to display de currency ISO 4217 code.

Exemples

iex> Moeda.to_string(:USD, 1000.5, thousand_separator: ",", decimal_separator: ".")
"$ 1,000.50"
iex> Moeda.to_string(:USD, 1000.5, display_currency_symbol: false)
"1.000,50"
iex> Moeda.to_string(:USD, 1000.5, display_currency_code: true)
"$ 1.000,50 USD"
iex> Moeda.to_string(:USD, 1000.5, display_currency_code: true, display_currency_symbol: false)
"1.000,50 USD"

The default values also can be set in the system Mix config.

Example:

iex> Application.put_env(:ex_dinheiro, :thousand_separator, ",")
iex> Application.put_env(:ex_dinheiro, :decimal_separator, ".")
iex> Moeda.to_string(:USD, 1000.5)
"$ 1,000.50"
iex> Application.put_env(:ex_dinheiro, :display_currency_symbol, false)
iex> Moeda.to_string(:USD, 5000.5)
"5,000.50"
iex> Application.put_env(:ex_dinheiro, :display_currency_code, true)
iex> Moeda.to_string(:USD, 10000.0)
"10,000.00 USD"

The options-style parameters override values in the system Mix config.

Example:

iex> Application.put_env(:ex_dinheiro, :thousand_separator, ",")
iex> Application.put_env(:ex_dinheiro, :decimal_separator, ".")
iex> Moeda.to_string(:USD, 1000.5)
"$ 1,000.50"
iex> Moeda.to_string(:BRL, 1000.5, thousand_separator: ".", decimal_separator: ",")
"R$ 1.000,50"