HasBigDecimal-0.2.0.0: A library for arbitrary precision decimal numbers.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.BigDecimal

Synopsis

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 

Fields

Instances

Instances details
Floating BigDecimal Source # 
Instance details

Defined in Data.BigFloating

Num BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

Read BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

Fractional BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

Real BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

Show BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

Eq BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

Ord BigDecimal Source # 
Instance details

Defined in Data.BigDecimal

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

divide Source #

Arguments

:: (BigDecimal, BigDecimal)

the tuple of dividend and divisor. I.e. (dividend, divisor)

-> RoundingAdvice

RoundingAdvice (i.e. a tuple of RoundingMode and the specified precision) defines the rounding behaviour. if Nothing if given as precision the maximum possible precision is used.

-> 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