diff --git a/Ledger/Amount.hs b/Ledger/Amount.hs index 132a2f22a..3de146346 100644 --- a/Ledger/Amount.hs +++ b/Ledger/Amount.hs @@ -60,12 +60,17 @@ showAmountRounded (Amount c q p) = (symbol c) ++ ({-punctuatethousands $ -}printf ("%."++show p++"f") q) showAmountRoundedOrZero :: Amount -> String -showAmountRoundedOrZero a@(Amount c _ _) = - let s = showAmountRounded a - noncurrency = drop (length $ symbol c) - nonnulls = filter (flip notElem "-+,.0") - iszero = (nonnulls $ noncurrency s) == "" - in if iszero then "0" else s +showAmountRoundedOrZero a + | isZeroAmount a = "0" + | otherwise = showAmountRounded a + +-- | is this amount zero, when displayed with its given precision ? +isZeroAmount :: Amount -> Bool +isZeroAmount a@(Amount c _ _) = nonzerodigits == "" + where + nonzerodigits = filter (flip notElem "-+,.0") quantitystr + quantitystr = withoutcurrency $ showAmountRounded a + withoutcurrency = drop (length $ symbol c) punctuatethousands :: String -> String punctuatethousands s = diff --git a/Ledger/Entry.hs b/Ledger/Entry.hs index c3c45ce97..08323223a 100644 --- a/Ledger/Entry.hs +++ b/Ledger/Entry.hs @@ -37,9 +37,8 @@ showEntryDescription e = (showDate $ edate e) ++ " " ++ (showDescription $ edesc showDate d = printf "%-10s" d showDescription s = printf "%-20s" (elideRight 20 s) --- | quick & dirty: checks entry's 0 balance only to 8 places isEntryBalanced :: Entry -> Bool -isEntryBalanced = ((0::Double)==) . read . printf "%0.8f" . quantity . sumLedgerTransactions . etransactions +isEntryBalanced = isZeroAmount . sumLedgerTransactions . etransactions autofillEntry :: Entry -> Entry autofillEntry e@(Entry _ _ _ _ _ ts _) =