diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index bf6a91de6..67efebb94 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -537,8 +537,8 @@ tests_Hledger_Data_Amount = TestList $ (a3 + a3) `is` usd (-2.46) sum [a1,a2,a3,-a3] `is` usd 0 -- highest precision is preserved - let ap1 = setAmountPrecision 1 $ usd 1 - ap3 = setAmountPrecision 3 $ usd 1 + let ap1 = usd 1 `withPrecision` 1 + ap3 = usd 1 `withPrecision` 3 (asprecision $ astyle $ sum [ap1,ap3]) `is` 3 (asprecision $ astyle $ sum [ap3,ap1]) `is` 3 -- adding different commodities assumes conversion rate 1 @@ -561,7 +561,7 @@ tests_Hledger_Data_Amount = TestList $ ,"adding mixed amounts" ~: do (sum $ map (Mixed . (\a -> [a])) [usd 1.25 - ,setAmountPrecision 0 $ usd (-1) + ,usd (-1) `withPrecision` 0 ,usd (-0.25) ]) `is` Mixed [amount{aquantity=0}] diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 443958aa8..e2c41e1e8 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -296,8 +296,8 @@ balanceTransaction styles t@Transaction{tpostings=ps} -- assign a balancing price. Use @@ for more exact output when possible. -- invariant: prices should always be positive. Enforced with "abs" = if length ramountsinunpricedcommodity == 1 - then TotalPrice $ setAmountPrecision maxprecision $ abs $ targetcommodityamount - else UnitPrice $ setAmountPrecision maxprecision $ abs $ targetcommodityamount `divideAmount` (aquantity unpricedamount) + then TotalPrice $ abs targetcommodityamount `withPrecision` maxprecision + else UnitPrice $ abs (targetcommodityamount `divideAmount` (aquantity unpricedamount)) `withPrecision` maxprecision | otherwise = NoPrice where unpricedcommodity = head $ filter (`elem` (map acommodity rsumamounts)) rcommoditiesinorder @@ -320,8 +320,8 @@ balanceTransaction styles t@Transaction{tpostings=ps} where conversionprice c | c == unpricedcommodity = if length bvamountsinunpricedcommodity == 1 - then TotalPrice $ setAmountPrecision maxprecision $ abs $ targetcommodityamount - else UnitPrice $ setAmountPrecision maxprecision $ abs $ targetcommodityamount `divideAmount` (aquantity unpricedamount) + then TotalPrice $ abs targetcommodityamount `withPrecision` maxprecision + else UnitPrice $ abs (targetcommodityamount `divideAmount` (aquantity unpricedamount)) `withPrecision` maxprecision | otherwise = NoPrice where unpricedcommodity = head $ filter (`elem` (map acommodity bvsumamounts)) bvcommoditiesinorder @@ -444,7 +444,7 @@ tests_Hledger_Data_Transaction = TestList $ concat [ ]) (showTransaction (txnTieKnot $ Transaction (parsedate "2010/01/01") Nothing False "" "x" "" [] - [Posting False "a" (Mixed [amt 1 `at` (setAmountPrecision 0 $ usd 2)]) "" RegularPosting [] Nothing + [Posting False "a" (Mixed [amt 1 `at` (usd 2 `withPrecision` 0)]) "" RegularPosting [] Nothing ,Posting False "b" missingmixedamt "" RegularPosting [] Nothing ] "")) @@ -480,7 +480,7 @@ tests_Hledger_Data_Transaction = TestList $ concat [ ] "") assertBool "balanceTransaction can infer conversion price" (isRight e) assertEqual "balancing conversion price is inferred" - (Mixed [usd 1.35 @@ (setAmountPrecision maxprecision $ eur 1)]) + (Mixed [usd 1.35 @@ (eur 1 `withPrecision` maxprecision)]) (case e of Right e' -> (pamount $ head $ tpostings e') Left _ -> error' "should not happen") diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index ddfc421cd..e44a1279e 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -577,7 +577,7 @@ amountp = try leftsymbolamount <|> try rightsymbolamount <|> nosymbolamount tests_amountp = [ "amountp" ~: do assertParseEqual (parseWithCtx nullctx amountp "$47.18") (usd 47.18) - assertParseEqual (parseWithCtx nullctx amountp "$1.") (setAmountPrecision 0 $ usd 1) + assertParseEqual (parseWithCtx nullctx amountp "$1.") (usd 1 `withPrecision` 0) ,"amount with unit price" ~: do assertParseEqual (parseWithCtx nullctx amountp "$10 @ €0.5")