When to use the Decimal library over floats? ðŸ¤”
Today I was wondering why we were using the [Decimal](https://hexdocs.pm/decimal/readme.html) library instead of my favorite faulty friend, the IEEE 754 floating-point number. Well, it says it right in the readme.
> Arbitrary precision decimal arithmetic.
But what is arbitrary precision, Dave?! ðŸ¥±
Well, http://0.30000000000000004.com/ can explain it better than I can, but let me illustrate with an example!
```elixir
iex(7)> 0.1 + 0.2
0.30000000000000004
```
ðŸ¤¢ðŸ¤®
No fear, the `Decimal` library provides arbitrary precision floating points for us!
```elixir
iex(1)> Decimal.add(Decimal.from_float(0.1), Decimal.from_float(0.2))
#Decimal<0.3>
```
davelucia
September 3, 2020