currency_formatter v0.4.8 CurrencyFormatter

This module takes care of formatting a number to a currency. You can also request a map containing all the formatting settings for a currency.

Summary

Functions

Formats a number to currency

Returns a map containing the full list of currencies

Returns a List with tuples that can be used as options for select

Returns a List with tuples that can be used as options for select

Returns a map with formatting settings for a currency

Returns the disambiguous symbol of a currency

Functions

format(number, currency \\ :USD)
format(Integer.t, Atom.t) :: String.t

Formats a number to currency

examples

iex> CurrencyFormatter.format(123456)
"US$1,234.56"

iex> CurrencyFormatter.format(654321, :eur)
"€6.543,21"

iex> CurrencyFormatter.format(654321, "AUD")
"A$6,543.21"
get_currencies()
get_currencies() :: Map.t

Returns a map containing the full list of currencies

examples

iex> currencies = CurrencyFormatter.get_currencies()
iex> Enum.count(currencies)
172
iex> currencies["usd"]
%{"alternate_symbols" => ["US$"], "decimal_mark" => ".",
"disambiguate_symbol" => "US$", "html_entity" => "$", "iso_code" => "USD",
"iso_numeric" => "840", "name" => "United States Dollar", "priority" => 1,
"smallest_denomination" => 1, "subunit" => "Cent", "subunit_to_unit" => 100,
"symbol" => "$", "symbol_first" => true, "thousands_separator" => ","}
get_currencies_for_select()
get_currencies_for_select() :: [{String.t, String.t}]

Returns a List with tuples that can be used as options for select

Examples

CurrencyFormatter.get_currencies_for_select()
["AED", "AFN", "ALL",...]
get_currencies_for_select(format)
get_currencies_for_select(Atom.t) :: [{String.t, String.t}]

Returns a List with tuples that can be used as options for select

Examples

CurrencyFormatter.get_currencies_for_select(:names)
[{"AED", "United Arab Emirates Dirham"}, {"AFN", "Afghan Afghani"} , {"ALL", "Albanian Lek"}, ...]

CurrencyFormatter.get_currencies_for_select(:symbols)
[{"AUD", "$"}, {"CAD", "$"}, {"USD", "$"},...]

CurrencyFormatter.get_currencies_for_select(:disambiguate_symbols)
[{"AUD", "A$"}, {"CAD", "C$"}, {"USD", "$"}, ...]
instructions(currency \\ :USD)
instructions(Atom.t) :: Map.t
instructions(String.t) :: Map.t

Returns a map with formatting settings for a currency

examples

iex> CurrencyFormatter.instructions(:EUR)
%{"alternate_symbols" => [], "decimal_mark" => ",", "html_entity" => "€",
"iso_code" => "EUR", "iso_numeric" => "978", "name" => "Euro", "priority" => 2,
"smallest_denomination" => 1, "subunit" => "Cent", "subunit_to_unit" => 100,
"symbol" => "€", "symbol_first" => true, "thousands_separator" => "."}
symbol(currency)

Returns the disambiguous symbol of a currency

Example

iex> CurrencyFormatter.symbol(:AUD)
"A$"