module Data.Tax.ATO.Rounding
( wholeDollars
, roundCents
) where
import Data.Tax
roundHalfUp :: (RealFrac a, Integral b) => a -> b
roundHalfUp :: forall a b. (RealFrac a, Integral b) => a -> b
roundHalfUp a
x =
let
(b
n, a
r) = forall a b. (RealFrac a, Integral b) => a -> (b, a)
properFraction a
x
in
case forall a. Num a => a -> a
signum (forall a. Num a => a -> a
abs a
r forall a. Num a => a -> a -> a
- a
0.5) of
-1 -> b
n
a
0 -> if a
r forall a. Ord a => a -> a -> Bool
< a
0 then b
n else b
n forall a. Num a => a -> a -> a
+ b
1
a
_ -> if a
r forall a. Ord a => a -> a -> Bool
< a
0 then b
n forall a. Num a => a -> a -> a
- b
1 else b
n forall a. Num a => a -> a -> a
+ b
1
wholeDollars :: (RealFrac a) => Money a -> Money a
wholeDollars :: forall a. RealFrac a => Money a -> Money a
wholeDollars = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Num a => Integer -> a
fromInteger forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> b
truncate)
roundCents :: (RealFrac a) => Money a -> Money a
roundCents :: forall a. RealFrac a => Money a -> Money a
roundCents = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((forall a. Fractional a => a -> a -> a
/ a
100)forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Num a => Integer -> a
fromInteger forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (RealFrac a, Integral b) => a -> b
roundHalfUp forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall a. Num a => a -> a -> a
* a
100))