2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE StandaloneDeriving #-}
5 {-# OPTIONS_GHC -fno-warn-orphans #-}
6 module Hcompta.Amount.Quantity where
14 import Data.Typeable ()
22 deriving instance Data Quantity
25 representation :: String
27 is_zero :: Quantity -> Bool
28 round :: Word8 -> Quantity -> Quantity
30 representation = "Double"
33 round n f = fromInteger $ round $ (f * (10^n)) / (10.0^^n)
35 is_zero = (== 0) . decimalMantissa
36 --is_zero decimal_places quantity =
37 -- floor quantity == 0 && -- NOTE: check integral part, in case of an overflow in roundTo'
38 -- 0 == roundTo' decimal_places quantity
40 -- roundTo' n f = fromInteger $ round $ f * (10 ^ n)
43 representation = "Decimal"
46 round = Data.Decimal.roundTo
48 is_zero = (== 0) . decimalMantissa
49 --is_zero decimal_places quantity =
50 -- (== 0) $ decimalMantissa $
51 -- Hcompta.Amount.Quantity.round decimal_places quantity