diff --git a/hledger-lib/Hledger/Data/Amount.hs b/hledger-lib/Hledger/Data/Amount.hs index e48554d62..8027219b1 100644 --- a/hledger-lib/Hledger/Data/Amount.hs +++ b/hledger-lib/Hledger/Data/Amount.hs @@ -83,9 +83,9 @@ module Hledger.Data.Amount ( showAmountWithZeroCommodity, showAmountDebug, showAmountWithoutPrice, - setAmountPrecision, + amountSetPrecision, withPrecision, - setFullPrecision, + amountSetFullPrecision, setAmountInternalPrecision, withInternalPrecision, setAmountDecimalPoint, @@ -129,7 +129,8 @@ module Hledger.Data.Amount ( showMixedAmountLinesB, wbToText, wbUnpack, - setMixedAmountPrecision, + mixedAmountSetPrecision, + mixedAmountSetFullPrecision, canonicaliseMixedAmount, -- * misc. ltraceamount, @@ -330,17 +331,17 @@ amountIsZero Amount{aquantity=q} = q == 0 -- | Set an amount's display precision, flipped. withPrecision :: Amount -> AmountPrecision -> Amount -withPrecision = flip setAmountPrecision +withPrecision = flip amountSetPrecision -- | Set an amount's display precision. -setAmountPrecision :: AmountPrecision -> Amount -> Amount -setAmountPrecision p a@Amount{astyle=s} = a{astyle=s{asprecision=p}} +amountSetPrecision :: AmountPrecision -> Amount -> Amount +amountSetPrecision p a@Amount{astyle=s} = a{astyle=s{asprecision=p}} -- | Increase an amount's display precision, if needed, to enough decimal places -- to show it exactly (showing all significant decimal digits, excluding trailing -- zeros). -setFullPrecision :: Amount -> Amount -setFullPrecision a = setAmountPrecision p a +amountSetFullPrecision :: Amount -> Amount +amountSetFullPrecision a = amountSetPrecision p a where p = max displayprecision naturalprecision displayprecision = asprecision $ astyle a @@ -841,8 +842,13 @@ ltraceamount :: String -> MixedAmount -> MixedAmount ltraceamount s = traceWith (((s ++ ": ") ++).showMixedAmount) -- | Set the display precision in the amount's commodities. -setMixedAmountPrecision :: AmountPrecision -> MixedAmount -> MixedAmount -setMixedAmountPrecision p = mapMixedAmount (setAmountPrecision p) +mixedAmountSetPrecision :: AmountPrecision -> MixedAmount -> MixedAmount +mixedAmountSetPrecision p = mapMixedAmount (amountSetPrecision p) + +-- | In each component amount, increase the display precision sufficiently +-- to render it exactly (showing all significant decimal digits). +mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount +mixedAmountSetFullPrecision = mapMixedAmount amountSetFullPrecision mixedAmountStripPrices :: MixedAmount -> MixedAmount mixedAmountStripPrices = mapMixedAmount (\a -> a{aprice=Nothing}) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 913f17022..dc4fcf5e8 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -1278,7 +1278,7 @@ journalApplyAliases aliases j = -- [ "P" -- , showDate (pddate pd) -- , T.unpack (pdcommodity pd) --- , (showAmount . setAmountPrecision maxprecision) (pdamount pd +-- , (showAmount . amountSetPrecision maxprecision) (pdamount pd -- ) -- ] diff --git a/hledger-lib/Hledger/Read/TimedotReader.hs b/hledger-lib/Hledger/Read/TimedotReader.hs index e8bc0eced..2e17f4100 100644 --- a/hledger-lib/Hledger/Read/TimedotReader.hs +++ b/hledger-lib/Hledger/Read/TimedotReader.hs @@ -182,7 +182,7 @@ entryp = do tstatus = Cleared, tpostings = [ nullposting{paccount=a - ,pamount=Mixed [setAmountPrecision (Precision 2) $ num hours] -- don't assume hours; do set precision to 2 + ,pamount=Mixed [amountSetPrecision (Precision 2) $ num hours] -- don't assume hours; do set precision to 2 ,ptype=VirtualPosting ,ptransaction=Just t } diff --git a/hledger-ui/Hledger/UI/TransactionScreen.hs b/hledger-ui/Hledger/UI/TransactionScreen.hs index c437e95d4..09ff044e8 100644 --- a/hledger-ui/Hledger/UI/TransactionScreen.hs +++ b/hledger-ui/Hledger/UI/TransactionScreen.hs @@ -72,7 +72,7 @@ tsDraw UIState{aopts=UIOpts{cliopts_=copts@CliOpts{reportspec_=rspec@ReportSpec{ _ -> [maincontent] where -- as with print, show amounts with all of their decimal places - t = transactionMapPostingAmounts setFullPrecision t' + t = transactionMapPostingAmounts amountSetFullPrecision t' maincontent = Widget Greedy Greedy $ do let prices = journalPriceOracle (infer_value_ ropts) j diff --git a/hledger/Hledger/Cli/Commands/Add.hs b/hledger/Hledger/Cli/Commands/Add.hs index eb11ad280..df6f65dc3 100644 --- a/hledger/Hledger/Cli/Commands/Add.hs +++ b/hledger/Hledger/Cli/Commands/Add.hs @@ -373,7 +373,7 @@ amountAndCommentWizard PrevInput{..} EntryState{..} = do balancingamt = negate $ sum $ map pamount realps where realps = filter isReal esPostings balancingamtfirstcommodity = Mixed $ take 1 $ amounts balancingamt showamt = - showMixedAmount . setMixedAmountPrecision + showMixedAmount . mixedAmountSetPrecision -- what should this be ? -- 1 maxprecision (show all decimal places or none) ? -- 2 maxprecisionwithpoint (show all decimal places or .0 - avoids some but not all confusion with thousands separators) ? diff --git a/hledger/Hledger/Cli/Commands/Close.hs b/hledger/Hledger/Cli/Commands/Close.hs index fa1b78122..911ab2fe9 100755 --- a/hledger/Hledger/Cli/Commands/Close.hs +++ b/hledger/Hledger/Cli/Commands/Close.hs @@ -93,7 +93,7 @@ close CliOpts{rawopts_=rawopts, reportspec_=rspec} j = do -- since balance assertion amounts are required to be exact, the -- amounts in opening/closing transactions should be too (#941, #1137) - precise = setFullPrecision + precise = amountSetFullPrecision -- interleave equity postings next to the corresponding closing posting, or put them all at the end ? interleaved = boolopt "interleaved" rawopts diff --git a/hledger/Hledger/Cli/Commands/Print.hs b/hledger/Hledger/Cli/Commands/Print.hs index 0e96d370b..fea2eaf5d 100644 --- a/hledger/Hledger/Cli/Commands/Print.hs +++ b/hledger/Hledger/Cli/Commands/Print.hs @@ -60,7 +60,7 @@ print' opts j = do -- that. For now we try to reverse it by increasing all amounts' decimal places -- sufficiently to show the amount exactly. The displayed amounts may have minor -- differences from the originals, such as trailing zeroes added. - let j' = journalMapPostingAmounts setFullPrecision j + let j' = journalMapPostingAmounts amountSetFullPrecision j case maybestringopt "match" $ rawopts_ opts of Nothing -> printEntries opts j' Just desc -> printMatch opts j' $ T.pack desc