Decimal: Decimal numbers with variable precision

[ bsd3, library, math ] [ Propose Tags ]

A decimal number has an integer mantissa and a negative exponent. The exponent can be interpreted as the number of decimal places in the value.

[Skip to Readme]
Versions 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.3.1, 0.4.1, 0.4.2, 0.5.1
Change log
Dependencies base (==4.*), deepseq [details]
License BSD-3-Clause
Copyright Paul Johnson, 2013, 2018.
Author Paul Johnson
Category Math
Home page
Uploaded by PaulJohnson at Wed Jan 3 15:33:05 UTC 2018
Distributions Arch:0.5.1, Debian:0.4.2, Fedora:0.4.2, LTSHaskell:0.5.1, NixOS:0.5.1, Stackage:0.5.1, openSUSE:0.5.1
Downloads 7395 total (65 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-01-03 [all 1 reports]
Hackage Matrix CI




Maintainer's Corner

For package maintainers and hackage trustees

Readme for Decimal-0.5.1

[back to package description]


Fixed-precision decimal numbers, where the precision is carried with the numbers at run-time.

The Decimal type is mainly intended for doing financial arithmetic where the number of decimal places may not be known at compile time (e.g. for a program that handles both Yen and Dollars) and the application must not drop pennies on the floor. For instance if you have to divide $10 between three people then one of them has to get $3.34.

The number of decimal places in a value is represented as a Word8, allowing for up to 255 decimal places. Functions preserve precision. Addition and subtraction operators return a result with the precision of the most precise argument, so 2.3 + 5.678 = 7.978. Multiplication and division use whatever precision is necessary up to 255 decimal places.

QuickCheck Specification

Data.Decimal includes a set of QuickCheck properties which act as both tests and a formal specification. To run the tests do:

cabal configure --enable-tests cabal build cabal test


stack test