Packages
fake_decimal
0.1.1
A drop-in :decimal module reproducing the legacy erlang_decimal API on top of the modern Elixir Decimal library, so legacy code and the Elixir decimal app can coexist in one BEAM node.
Current section
Files
Jump to
Current section
Files
fake_decimal
README.md
README.md
# FakeDecimal
If you deal with legacy Erlang code, you may know the old `erlang_decimal`
library. On Hex it's published as `erlang_decimal`, but it registers its OTP
application (and its module) under the plain name `decimal` — the same name the
modern Elixir `decimal` library uses for its own OTP application. Since a BEAM
node can't run two applications with the same name, you can't depend on both at
once.
`fake_decimal` solves this by providing the exact same API as the old `decimal`
module, implemented on top of the modern Elixir `Decimal` library. Depend on
`fake_decimal` (which pulls in the real `decimal` app) instead of
`erlang_decimal`, and your legacy code can keep calling `:decimal.add/2`,
`:decimal.round/3`, and so on without ever knowing it's talking to the new
library underneath.
## Installation
Add `fake_decimal` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:fake_decimal, "~> 0.1.1"}
]
end
```
Documentation is available on [HexDocs](https://hexdocs.pm/fake_decimal).
Property-based tests compare `fake_decimal` against a real instance of
`erlang_decimal`, loaded in a separate node, to make sure the two behave
identically.
See the @moduledoc in `lib/fake_decimal.ex` for the full API and the handful of
intentional deviations from the original.