Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Elixir
  3. decimal

decimal

Apache-2.0Elixirv3.1.0

Arbitrary precision decimal arithmetic library for Elixir, representing numbers exactly with sign, coefficient, and exponent.

Visit WebsiteGitHubGitHub
478 stars109 forks0 contributors

What is decimal?

Decimal is an Elixir library for arbitrary precision decimal arithmetic, enabling exact representation of numbers of any size and decimal places. It solves floating-point inaccuracies by using a three-integer internal representation (sign, coefficient, exponent), making it essential for financial, scientific, and other precision-sensitive calculations.

Target Audience

Elixir developers working on applications requiring exact decimal calculations, such as financial systems, scientific computations, or any domain where rounding errors are unacceptable.

Value Proposition

Developers choose Decimal for its exact representation of decimals, configurable precision and rounding via a context system, and adherence to decimal arithmetic standards, ensuring reliable and predictable results without floating-point errors.

Overview

Arbitrary precision decimal arithmetic

Use Cases

Best For

  • Financial applications where exact decimal calculations are critical, such as currency handling or accounting systems.
  • Scientific computations requiring arbitrary precision and control over rounding algorithms.
  • Elixir projects needing configurable precision and error handling for decimal arithmetic via a context system.
  • Avoiding floating-point inaccuracies in comparisons and operations by using exact decimal representation.
  • Implementing domain-specific rounding rules (e.g., half_up, floor) in calculations with controlled precision.
  • Handling exceptional conditions like division by zero with customizable flags and trap enablers for error management.

Not Ideal For

  • Real-time systems prioritizing speed over exact precision, as arbitrary precision arithmetic is slower than floating-point.
  • Projects heavily reliant on Elixir's standard comparison operators without willingness to refactor for dedicated functions.
  • Applications with strict memory constraints, since Decimal's internal representation can be more memory-intensive than floats.
  • Teams seeking plug-and-play numerical libraries without managing process-specific context configurations.

Pros & Cons

Pros

Exact Decimal Representation

Uses a three-integer internal model (sign, coefficient, exponent) to represent numbers exactly, eliminating floating-point rounding errors as demonstrated in the concept examples.

Configurable Precision Control

Allows setting maximum decimal digits via the context system, enabling precise control over calculation results, shown in the precision and rounding examples.

Flexible Rounding Algorithms

Supports multiple rounding methods like :half_up and :floor, which can be set in the context to tailor rounding behavior for specific needs.

Robust Error Management

Includes flags and trap enablers to signal and optionally raise errors for conditions like division_by_zero, enhancing reliability in error-prone calculations.

Cons

Process-Local Context

Stores configuration in the process dictionary, which complicates concurrent usage and requires careful management in multi-process environments.

Performance Overhead

Arbitrary precision calculations are inherently slower than native floating-point operations, making it unsuitable for high-performance numerical tasks.

Verbose Comparison Syntax

Requires using specific functions like Decimal.compare/2 instead of standard operators, increasing code verbosity and potential for misuse.

Documentation Gaps

The README has incomplete sections, such as the 'TODO' on mitigating rounding errors, which may leave users without full guidance on advanced topics.

Frequently Asked Questions

Quick Stats

Stars478
Forks109
Contributors0
Open Issues0
Last commit2 days ago
CreatedSince 2013

Tags

#elixir#precision#decimal-arithmetic#arbitrary-precision#error-handling#rounding#numerical-computing#context-management#math-library#financial-calculations

Built With

E
Elixir

Links & Resources

Website

Included in

Elixir13.1k
Auto-fetched 1 day ago

Related Projects

moneymoney

Elixir library for working with Money safer, easier, and fun... Is an interpretation of the Fowler's Money pattern in fun.prog.

Stars848
Forks144
Last commit23 days ago
inflexinflex

An Inflector library for Elixir

Stars384
Forks81
Last commit2 years ago
uuiduuid

UUID generator and utilities for Elixir

Stars368
Forks83
Last commit1 year ago
hashidshashids

Stringify your ids

Stars282
Forks16
Last commit2 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub