ENH actually use percents
This commit is contained in:
parent
9a1dd1ac3e
commit
b3276132e3
|
@ -327,7 +327,7 @@ allocatePre precision gross = L.mapAccumR go M.empty
|
||||||
p = preValue faValue
|
p = preValue faValue
|
||||||
v =
|
v =
|
||||||
if prePercent faValue
|
if prePercent faValue
|
||||||
then roundPrecision 3 p * gross
|
then (roundPrecision 3 p / 100) * gross
|
||||||
else roundPrecision precision p
|
else roundPrecision precision p
|
||||||
in (mapAdd_ c v m, f {faValue = v})
|
in (mapAdd_ c v m, f {faValue = v})
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ allocateTax precision gross deds = fmap (fmap go)
|
||||||
go TaxValue {tvCategories, tvMethod} =
|
go TaxValue {tvCategories, tvMethod} =
|
||||||
let agi = gross - sum (mapMaybe (`M.lookup` deds) tvCategories)
|
let agi = gross - sum (mapMaybe (`M.lookup` deds) tvCategories)
|
||||||
in case tvMethod of
|
in case tvMethod of
|
||||||
TMPercent p -> roundPrecision 3 p * agi
|
TMPercent p -> roundPrecision 3 p / 100 * agi
|
||||||
TMBracket TaxProgression {tpDeductible, tpBrackets} ->
|
TMBracket TaxProgression {tpDeductible, tpBrackets} ->
|
||||||
foldBracket precision (agi - roundPrecision precision tpDeductible) tpBrackets
|
foldBracket precision (agi - roundPrecision precision tpDeductible) tpBrackets
|
||||||
|
|
||||||
|
@ -371,14 +371,17 @@ allocatePost
|
||||||
allocatePost precision aftertax = fmap (fmap go)
|
allocatePost precision aftertax = fmap (fmap go)
|
||||||
where
|
where
|
||||||
go PosttaxValue {postValue, postPercent} =
|
go PosttaxValue {postValue, postPercent} =
|
||||||
let v = postValue in if postPercent then aftertax * roundPrecision 3 v else roundPrecision precision v
|
let v = postValue
|
||||||
|
in if postPercent
|
||||||
|
then aftertax * roundPrecision 3 v / 100
|
||||||
|
else roundPrecision precision v
|
||||||
|
|
||||||
foldBracket :: Natural -> Rational -> [TaxBracket] -> Rational
|
foldBracket :: Natural -> Rational -> [TaxBracket] -> Rational
|
||||||
foldBracket precision agi bs = fst $ foldr go (0, agi) $ L.sortOn tbLowerLimit bs
|
foldBracket precision agi bs = fst $ foldr go (0, agi) $ L.sortOn tbLowerLimit bs
|
||||||
where
|
where
|
||||||
go TaxBracket {tbLowerLimit, tbPercent} (acc, remain) =
|
go TaxBracket {tbLowerLimit, tbPercent} (acc, remain) =
|
||||||
let l = roundPrecision precision tbLowerLimit
|
let l = roundPrecision precision tbLowerLimit
|
||||||
p = roundPrecision 3 tbPercent
|
p = roundPrecision 3 tbPercent / 100
|
||||||
in if remain < l then (acc + p * (remain - l), l) else (acc, remain)
|
in if remain < l then (acc + p * (remain - l), l) else (acc, remain)
|
||||||
|
|
||||||
data FlatAllocation v = FlatAllocation
|
data FlatAllocation v = FlatAllocation
|
||||||
|
|
Loading…
Reference in New Issue