slouchpie

slouchpie

Money libraries - which do you use and why?

There seem to be 2 Elixir “Money” libs:

and neither one makes reference to the other.

Personally, I use the kipcole9 one, a.k.a :ex_money because it seems to be more well-considered (it uses :cldr_utils) and the author is very active here (Ex_money - money with currency type).

However, my library of choice is “less popular” (less stars and forks) on Github.

So I am wondering what other people think. Is one library better than the other? Is it bad to have 2 competing libraries doing much the same thing? Is it possible to achieve approximate consensus on which library deserves to be the de-facto money library for Elixir?

Most Liked

kip

kip

ex_cldr Core Team

I do try to be as clear as possible in documentation about the purpose and intent of ex_money. Always happy to accept a PR that makes it clearer! (I’m the author).

Introduction to Money

Money implements a set of functions to store, retrieve, convert and perform arithmetic
on a %Money{} type that is composed of an ISO 4217 currency code and a currency amount.

Money is opinionated in the interests of serving as a dependable library that can underpin accounting and financial applications.

How is this opinion expressed?

  1. Money must always have both a amount and a currency code.

  2. The currency code must always be a valid ISO4217 code. Current and historical currency codes can be used. See the ISO Currency for more information. You can also identify the relevant codes by:

    • Money.known_currencies/0 returns all the currency codes known to Money
    • Money.known_current_currencies/0 returns the currency codes currently in use
    • Money.known_historic_currencies/0 returns the list of historic currency codes
    • Money.known_tender_currencies/0 returns the list of currencies known to be legal tender
  3. Money arithmetic can only be performed when both operands are of the same currency.

  4. Money amounts are represented as a Decimal.

  5. Money can be serialised to the database as a composite Postgres type that includes both the amount and the currency. For MySQL, money is serialized into a json column with the amount converted to a string to preserve precision since json does not have a decimal type. Serialization is entirely optional.

  6. All arithmetic functions work on a Decimal. No rounding occurs automatically (unless expressly called out for a function, as is the case for Money.split/2).

  7. Explicit rounding obeys the rounding rules for a given currency. The rounding rules are defined by the Unicode consortium in its CLDR repository as implemented by the hex package ex_cldr. These rules define the number of fractional digits for a currency and the rounding increment where appropriate.

  8. Money output string formatting output using the hex package ex_cldr that correctly rounds to the appropriate number of fractional digits and to the correct rounding increment for currencies that have minimum cash increments (like the Swiss Franc and Australian Dollar)

LostKobrakai

LostKobrakai

My take is that the :money library is mostly providing a datatype, while :ex_money is a toolkit of dealing with money, especially in an internationalized fashion.

Some of those factors:

  • Available currencies
    In :money the list of currencies is static/hardcoded and you can only add additional ones. :ex_money depends on :cldr for currencies instead of maintaining a list on it’s own and also has means for adding additional ones.
  • Rounding rules (a.k.a. business rules of currencies)
    With :cldr in the back :ex_cldr does not only know the number of decimal places a currency uses, but also about things like alternate rounding rules, like when cash is supposed to round differently than e.g. accounting.
  • Formatting
    :money does only support a single set of default formatting or customized per API call. :ex_money again uses :cldr to adjust formatting to settings matching a certain locale (like the users’).

So all in all it’s :ex_money for me if only for the fact of harnessing the knowledge of a unicode maintained database of those mentioned things as opposed to a library maintainer having a (likely worse) maintained copy of it.

11
Post #5
slouchpie

slouchpie

I think the only thing lacking is for each library to make some reference to the other.

For example…

:money could have this in its README

Looking for something more comprehensive and globally applicable? Look at :ex_money

and :ex_money could have this in its README

Looking for something simple and lighter without any :cldr deps? Look at :money

something like that?

Where Next?

Popular in Discussions Top

matthias_toepp
I’d love to hear what people think about Wisp, the new Gleam web framework started by Gleam’s primary creator Louis Pilfold. Gleam, alon...
New
jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
axelson
Decided against including more info in the title, but the gist is that Plataformatec sponsored projects will continue with the assets bei...
New
ejpcmac
I have discovered Nix last month and I am currently on my way to migrating to it—both on macOS at home and the full NixOS distrubution at...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
kostonstyle
Hi all How can I compare haskell with elixir, included tools, webservices, ect. Thanks
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New

Other popular topics Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

We're in Beta

About us Mission Statement