How to get accounts where balance > 0 using ex_money?

That’s pure gold, thanks for posting your thoughts @kip! Since you are also the author of CLDR and friends I would assume that localization or representation of those values is not something that particularly concerns you, right!? How are you dealing with localization today if you don’t mind me asking? (I also don’t want to hijack the thread, so maybe we should open another one to discuss this - it could be useful to others in the future). Cheers!

ex_money is built upon ex_cldr so localisation is an intrinsic part of the library:

iex> m = Money.new(:USD, 100)
Money.new(:USD, "100")

# Locale-specific formatting
iex> Money.to_string(m, locale: :de)
{:ok, "100,00 $"}

iex> Money.to_string(m, locale: :de, format: :long)
{:ok, "100 US-Dollar"}

iex> Money.to_string(m, locale: :es, format: :long)
{:ok, "100 dólares estadounidenses"}

# Locale specific parsing (which take care to understand
# the locales decimal and grouping separators
iex> Money.parse("100,00 $", locale: :de)
Money.new(:USD, "100.00")

# Return display names that can be used in UI for
# example, as column headings
iex> Cldr.Currency.display_name :USD, locale: :de
{:ok, "US-Dollar"}

iex> Cldr.Currency.display_name :USD, locale: :ar
{:ok, "دولار أمريكي"}

And although not strictly localisation, ex_money knows all the ISO4217 currency formats so rounding is done to the correct number of digits when required and formatting displays the correct number of decimals. For example:

# JPY has no decimal places (in common use at least)
iex> Money.to_string Money.new(:JPY, 54321)
{:ok, "¥54,321"}

# Tunisian Dinar has three decimal places
iex> Money.to_string Money.new(:TND, "1000.12345")
{:ok, "TND 1,000.123"}

# Swiss Franc cash smallest unit is 5 centimes.
# Rounding is `:half_even`
iex> Money.round Money.new(:CHF, "123.73"), currency_digits: :cash
Money.new(:CHF, "123.75")
5 Likes