Safe and very efficient arithmetic operations on fixed decimal point numbers

LTS Haskell 21.13:
Stackage Nightly 2023-09-27:
Latest on Hackage:

See all snapshots safe-decimal appears in

BSD-3-Clause licensed by Alexey Kuleshevich
Maintained by
This version can be pinned in stack with:safe-decimal-,2017

Module documentation for


Language Travis
GitHub top language Travis
Package Hackage Nightly LTS
safe-decimal Hackage Nightly Nightly

An implementation of a decimal point data type, that is backed by any custom integral type. It is safe, because things like integer overflows, underflows, division by zero etc. are checked for during the runtime and are prevented in pure code.


Changelog for safe-decimal


  • Add arithError
  • Add RoundHalfToZero and RoundHalfFromZero rounding strategies.
  • Conversion from Scientific normalizes the input and is more resilient to unbounded computation for bounded Decimal result.


  • Add Arith monad and corresponding functions.
  • Make rounding dependent on precision type (extra type argument to the Round type class)
  • Rename RoundFloor to RoundDown (with Floor as synonym)
  • Rename Truncate to RoundToZero (with Truncate as synonym)
  • Fix conversion fromRational to throw Underflow instead of rounding. Without this fix there was unexpected behavior on negative numbers.
  • Addition of scaleUp and scaleUpBounded
  • Addition of toFixedDecimal, fromFixedDecimal and fromFixedDecimalBounded
  • Many function renames, just to make sure they all follow the same convention.
  • Fix RoundHalfUp algorithm
  • Addition of RoundHalfDown and RoundHalfEven


Initial release