mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 15:14:49 +03:00
better zero amount checking
This commit is contained in:
parent
cf194e6b60
commit
7db9c4c910
@ -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 =
|
||||
|
@ -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 _) =
|
||||
|
Loading…
Reference in New Issue
Block a user