talira

Decimal (Elixir)

Arbitrary precision decimal arithmetic

open sourceApache-2.0free

Decimal is the arbitrary precision decimal arithmetic library for Elixir. It represents each number as a sign, a coefficient and an exponent, so values of any size and with any number of decimal places are exact, and you choose how many digits of precision a calculation keeps. It parses, casts and formats decimals, and offers bounded parsing (a maximum number of digits and exponent) for untrusted input, since a compact value like 1e1000000 can take a lot of memory or CPU to expand.

Problems it solves

  • do money calculations in Elixir without floating point rounding errors
  • store and compute exact decimal values from a database in Elixir
  • parse decimal numbers from user input safely

Features

  • exact decimal numbers of any size
  • configurable precision for calculations
  • parse, cast and format decimals
  • bounded parsing for untrusted input