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 :: Word8 -> Quantity -> Bool
29 round :: Word8 -> Quantity -> Quantity
31 representation = "Double"
34 round :: fromInteger $ round $ (f * (10^n)) / (10.0^^n)
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 decimal_places quantity =
49 (== 0) $ decimalMantissa $
50 Hcompta.Model.Amount.Quantity.round decimal_places quantity