rename amount show functions

This commit is contained in:
Simon Michael 2008-10-15 00:37:38 +00:00
parent 782d05aa61
commit aac492c746
5 changed files with 11 additions and 11 deletions

View File

@ -124,7 +124,7 @@ showBalanceReport opts args l = acctsstr ++ totalstr
acctsstr = concatMap (showAccountTreeWithBalances acctnamestoshow) $ subs treetoshow
totalstr = if isZeroAmount total
then ""
else printf "--------------------\n%20s\n" $ showAmountRounded total
else printf "--------------------\n%20s\n" $ showAmount total
showingsubs = ShowSubs `elem` opts
pats@(apats,dpats) = parseAccountDescriptionArgs args
maxdepth = if null args && not showingsubs then 1 else 9999

View File

@ -46,12 +46,12 @@ import Ledger.Commodity
amounttests = TestList [
]
instance Show Amount where show = showAmountRounded
instance Show Amount where show = showAmount
-- | Get the string representation of an amount, based on its commodity's
-- display settings.
showAmountRounded :: Amount -> String
showAmountRounded (Amount (Commodity {symbol=sym,side=side,spaced=spaced,precision=p}) q)
showAmount :: Amount -> String
showAmount (Amount (Commodity {symbol=sym,side=side,spaced=spaced,precision=p}) q)
| side==L = printf "%s%s%s" sym space quantity
| side==R = printf "%s%s%s" quantity space sym
where
@ -60,17 +60,17 @@ showAmountRounded (Amount (Commodity {symbol=sym,side=side,spaced=spaced,precisi
punctuatethousands = id
-- | Get the string representation of an amount, rounded, or showing just "0" if it's zero.
showAmountRoundedOrZero :: Amount -> String
showAmountRoundedOrZero a
showAmountOrZero :: Amount -> String
showAmountOrZero a
| isZeroAmount a = "0"
| otherwise = showAmountRounded a
| otherwise = showAmount 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 = withoutsymbol $ showAmountRounded a
quantitystr = withoutsymbol $ showAmount a
withoutsymbol = drop (length $ symbol c) -- XXX
punctuatethousands :: String -> String

View File

@ -83,7 +83,7 @@ showEntry e =
showtxn t = showacct t ++ " " ++ (showamount $ tamount t) ++ (showcomment $ tcomment t)
showtxnnoamt t = showacct t ++ " " ++ (showcomment $ tcomment t)
showacct t = " " ++ (showaccountname $ taccount t)
showamount = printf "%12s" . showAmountRounded
showamount = printf "%12s" . showAmount
showaccountname s = printf "%-34s" s
showcomment s = if (length s) > 0 then " ; "++s else ""

View File

@ -21,7 +21,7 @@ showLedgerTransaction :: RawTransaction -> String
showLedgerTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ tamount t)
where
showaccountname = printf "%-22s" . elideRight 22
showamount = printf "%12s" . showAmountRoundedOrZero
showamount = printf "%12s" . showAmountOrZero
elideRight width s =
case length s > width of

View File

@ -46,5 +46,5 @@ showTransactionAndBalance t b =
(replicate 32 ' ') ++ (showLedgerTransaction $ RawTransaction (account t) (amount t) "") ++ (showBalance b)
showBalance :: Amount -> String
showBalance b = printf " %12s" (showAmountRoundedOrZero b)
showBalance b = printf " %12s" (showAmountOrZero b)