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