Decimal numbers with variable precision
|Version on this page:||0.5.1|
|LTS Haskell 20.24:||0.5.2|
|Stackage Nightly 2023-06-08:||0.5.2|
|Latest on Hackage:||0.5.2|
Module documentation for 0.5.1
Fixed-precision decimal numbers, where the precision is carried with the numbers at run-time.
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
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.
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
Put test suite under
- Minor fixes to allow compilation under other versions of GHC.
- Added instance of
Control.DeepSeq, and hence a dependency on the
deepseqpackage, thanks to Jeff Shaw (shawjef3 at msu.edu).
Multiplication now returns an exact result, increasing precision if necessary.
These changes alter the API. Hence the increment to the major version number.
Thanks to Alexey Uimanov (s9gf4ult at gmail.com).
Readinstance. Now handles
readsonly returns a single parse.
decimalConvertnow returns a Maybe value. The old version has been renamed to “unsafeDecimalConvert.
Bankers’ Rounding implemented in “roundTo”. This rounds values ending in “5” to the nearest even number, in line with the behaviour of “Prelude.round”. This is potentially a breaking change for software that depends on the old behavior, so the minor version number has been bumped.
Readinstance now handles leading spaces properly.
Fixed compiler warnings in test suite.
roundTo'which allows for
ceilingbehaviour when rounding.