slouchpie

slouchpie

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?

First Post!

egze

egze

I remember that kipcole9/money took much more time to compile and we replaced it with plain Decimal. Decimal — Decimal v3.1.1

I used elixirmoney/money also before and it just worked.

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 #4
slouchpie

slouchpie OP

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?

Last Post!

lukaszsamson

lukaszsamson

ElixirLS Core Team

In my company (fintech domain) mostly Decimal as integrates nicely with ecto. The library used to be buggy (I and my coworkers authored a few PRs) but that’s no longer the case. The biggest problem with Decimal now is performance. In case of performance sensitive code we use plain old integers or even NIFs.

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New
marciol
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews