kip
Ex_money - money with currency type
ex_money is a package to manage a money data type and provide localised formatting, arithmetic, exchange rates, basic financial calculations and serialization with a special attention on preserving precision.
CLDR data drives the localisation capabilities. As a result ex_money knows about each currencies precision, separators, grouping and symbols in any of about 500 locales.
Version 3.2.4 is out this week with a new ability to parse money strings. Some examples follow:
# These are the strings available for a given currency
# and locale that are recognised during parsing
iex> Cldr.Currency.strings_for_currency :AUD, "de"
["aud", "au$", "australischer dollar", "australische dollar"]
# Parsing can be localised
iex> Money.parse "12 346 dollar australien", locale: "fr"
#Money<:AUD, 12346>
iex> Money.parse "A$ 12346", locale: "en"
#Money<:AUD, 12346>
# Note that the decimal separator in the "de" locale
# is a `.`
iex> Money.parse "AU$ 12346,45", locale: "de"
#Money<:AUD, 12346.45>
# Round trip formatting is supported
iex> {:ok, string} = Cldr.Number.to_string 1234, Money.Cldr, currency: :AUD
{:ok, "A$1,234.00"}
iex> Money.parse string
#Money<:AUD, 1234.00>
# Fuzzy matching is possible
iex> Money.parse("100 eurosports", fuzzy: 0.8)
#Money<:EUR, 100>
iex> Money.parse("100 eurosports", fuzzy: 0.9)
{:error,
{Money.Invalid, "Unable to create money from \"eurosports\" and \"100\""}}
# Eligible currencies can be filtered by type
iex> Money.parse("100 eurosports", fuzzy: 0.8, currency_filter: [:current, :tender])
#Money<:EUR, 100>
Most Liked
kip
Finally. finally. ex_money is updated to be based upon localize, not ex_cldr.
Updated libraries
I’m definitely looking for any feedback on ex_money before I publish the final 6.0 release.
Changes
Overall there are no functional changes, only platform changes:
- add
localize - remove
ex_cldr - move all custom and private currency registry functions to
Money.Currency. They were removed fromLocalize.Currency. This is a much cleaner responsibility model. - remove
gringottsoptional dependency - remove
:json_libraryconfiguration (standardise on:json) - requires at least Elixir 1.17
kip
ex_money just hit a million downloads on hex.pm. Small beer in comparison to its older sibling money but still - thank you to everyone who has found value in it and given it your support.
First commit was June 19, 2016 so it’s been seven years in the making
The last release was 3 weeks ago and there have been no issues raised since March. So its in good shape, still under active support and feature requests are always welcome.
kip
I’ve just published the first in a new series of libraries focused on input. First up is ex_money_input. Soon to come is one for plain numbers (which will be part of a new library, localize_inputs).
It’s the form-input layer for the elixir-money family. It rounds out the trio: ex_money for the data type, ex_money_sql for Ecto persistence, and now ex_money_input for users actually typing a value into a form.
Example component usage
<.money_input
form={@form}
field={:price}
default_currency={:USD}
currency_picker={true}
preferred_currencies={[:USD, :EUR, :GBP, :JPY]}
/>
Features
- A
<.money_input>HEEx component with a paired<.currency_picker>. Locale determines the separators, symbol position, fractional digits (USD 2, JPY 0, BHD 3), and even the digit system (Arabic, Persian). - A small JS hook wrapping AutoNumeric (MIT, Alexandre Bonneau) for live formatting and cursor preservation. Optional — without it the input still works server-side. But
AutoNumericdoes a great job on the UX side, respecting and understanding different locale grouping and fraction separators. - An Ecto changeset bridge (
cast_money/3,validate_money/3) with currency-aware precision and bounds. - A headless cast/validate/currency layer that’s usable without Phoenix.
Money Input Playground
There’s a Plug-based visualizer that demos every component across CLDR locales and currencies.
It’s deployed at https://elixir-money-input.fly.dev so you can explore its potential use for your projects.
Links
Docs: https://hexdocs.pm/ex_money_input
Source: https://github.com/ex-money/money_input
Integration guide: https://hexdocs.pm/ex_money_input/integration.html
Feedback welcome — particularly on the locales you actually ship to. The CLDR coverage is wide but there’s always a corner case.
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










