2 {-# LANGUAGE DeriveDataTypeable #-}
3 {-# LANGUAGE FlexibleInstances #-}
4 {-# LANGUAGE StandaloneDeriving #-}
5 {-# OPTIONS_GHC -fno-warn-orphans #-}
6 module Hcompta.Amount.Quantity where
14 import Data.Eq (Eq(..))
15 import Data.String (String)
17 import Data.Typeable ()
26 deriving instance Data Quantity
29 representation :: String
31 is_zero :: Quantity -> Bool
32 round :: Word8 -> Quantity -> Quantity
34 representation = "Double"
37 round n f = fromInteger $ round $ (f * (10^n)) / (10.0^^n)
39 is_zero = (== 0) . decimalMantissa
40 --is_zero decimal_places quantity =
41 -- floor quantity == 0 && -- NOTE: check integral part, in case of an overflow in roundTo'
42 -- 0 == roundTo' decimal_places quantity
44 -- roundTo' n f = fromInteger $ round $ f * (10 ^ n)
47 representation = "Decimal"
50 round = Data.Decimal.roundTo
52 is_zero = (== 0) . decimalMantissa
53 --is_zero decimal_places quantity =
54 -- (== 0) $ decimalMantissa $
55 -- Hcompta.Amount.Quantity.round decimal_places quantity