Dinheiro v0.1.6 Moeda View Source
Link to this section Summary
Types
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
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
Return a map from an atom or string that represents an ISO 4217 code.
Examples
iex> Moeda.find(:BRL)
%Moeda{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> Moeda.find("BRL")
%Moeda{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)
%Moeda{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> Moeda.find("brl")
%Moeda{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: %Moeda{nome: "Bitcoin", simbolo: '฿', codigo: "XBT", codigo_iso: 0, expoente: 8} }
iex> Application.put_env(:ex_dinheiro, :unofficial_currencies, moedas)
iex> Moeda.find("xbt")
%Moeda{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)
%Moeda{nome: "Brazilian Real", simbolo: 'R$', codigo: "BRL", codigo_iso: 986, expoente: 2}
iex> moedas = %{ BRL: %Moeda{nome: "Moeda do Brasil", simbolo: 'BR$', codigo: "BRL", codigo_iso: 986, expoente: 4}, USD: %Moeda{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)
%Moeda{nome: "Moeda do Brasil", simbolo: 'BR$', codigo: "BRL", codigo_iso: 986, expoente: 4}
iex> Moeda.find(:USD)
%Moeda{nome: "Moeda do EUA", simbolo: 'US$', codigo: "USD", codigo_iso: 986, expoente: 3}
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
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
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
- defaulttrue
, put tofalse
to hide de currency symbol.display_currency_code
- defaultfalse
, put totrue
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"