Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.BigDecimal
Synopsis
- data BigDecimal = BigDecimal {}
- data RoundingMode
- type RoundingAdvice = (RoundingMode, Maybe Natural)
- precision :: BigDecimal -> Natural
- trim :: Natural -> BigDecimal -> BigDecimal
- nf :: BigDecimal -> BigDecimal
- divide :: (BigDecimal, BigDecimal) -> RoundingAdvice -> BigDecimal
- roundBD :: BigDecimal -> RoundingAdvice -> BigDecimal
- fromRatio :: Rational -> RoundingAdvice -> BigDecimal
- halfUp :: Natural -> RoundingAdvice
- fromString :: String -> BigDecimal
- fromStringMaybe :: String -> Maybe BigDecimal
- fromNatural :: Num a => Natural -> a
- matchScales :: (BigDecimal, BigDecimal) -> (BigDecimal, BigDecimal)
Documentation
data BigDecimal Source #
BigDecimal is represented by an unscaled Integer value and a Natural that defines the scale E.g.: (BigDecimal 1234 2) represents the decimal value 12.34.
Constructors
BigDecimal | |
Instances
data RoundingMode Source #
RoundingMode defines how to handle loss of precision in divisions or explicit rounding.
Constructors
UP | Rounding mode to round away from zero. |
DOWN | Rounding mode to round towards zero. |
CEILING | Rounding mode to round towards positive infinity. |
FLOOR | Rounding mode to round towards negative infinity. |
HALF_UP | Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round up. |
HALF_DOWN | Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. |
HALF_EVEN | Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. |
PRECISE | Rounding mode to assert that the requested operation has an exact result, hence no rounding is applied. |
type RoundingAdvice = (RoundingMode, Maybe Natural) Source #
A RoundingAdvice is interpreted by divisions and rounding operations to specify the expected loss of precision and the rounding behaviour.
RoundingAdvice is a pair of a RoundingMode
and a target precision of type Maybe
Natural
. The precision defines the number of digits after the decimal point.
If Nothing
is given as precision all decimal digits are to be preserved, that is precision is not limited.
precision :: BigDecimal -> Natural Source #
returns the number of digits of a BigDecimal.
trim :: Natural -> BigDecimal -> BigDecimal Source #
removes trailing zeros from a BigDecimals intValue by decreasing the scale
nf :: BigDecimal -> BigDecimal Source #
computes the normal form of a BigDecimal
Arguments
:: (BigDecimal, BigDecimal) | the tuple of dividend and divisor. I.e. (dividend, divisor) |
-> RoundingAdvice |
|
-> BigDecimal | the resulting BigDecimal |
divide two BigDecimals and applies the RoundingAdvice
(i.e. a tuple of RoundingMode
and the specified precision) for rounding.
roundBD :: BigDecimal -> RoundingAdvice -> BigDecimal Source #
round a BigDecimal according to a RoundingAdvice
to n
digits applying the RoundingMode
rMode
fromRatio :: Rational -> RoundingAdvice -> BigDecimal Source #
creates a BigDecimal from a Rational
value. RoundingAdvice
defines precision and rounding mode.
halfUp :: Natural -> RoundingAdvice Source #
construct a RoundingAdvice
for rounding HALF_UP
with scl
decimal digits
fromString :: String -> BigDecimal Source #
read a BigDecimal from a human readable decimal notation.
e.g. fromString "3.14"
yields 'BigDecimal 314 2'
fromStringMaybe :: String -> Maybe BigDecimal Source #
read a BigDecimal from a human readable decimal notation.
e.g. fromString "3.14"
yields 'BigDecimal 314 2'
fromNatural :: Num a => Natural -> a Source #
convert a Natural to any numeric type a
matchScales :: (BigDecimal, BigDecimal) -> (BigDecimal, BigDecimal) Source #
match the scales of a tuple of BigDecimals