try showing integral "maxprecision" amounts without the .0 (except in add's defaults, where it helps)
This commit is contained in:
parent
3a0dffa7eb
commit
b2f439eb11
@ -53,6 +53,7 @@ module Hledger.Data.Amount (
|
||||
isReallyZeroMixedAmountCost,
|
||||
isZeroMixedAmount,
|
||||
maxprecision,
|
||||
maxprecisionwithpoint,
|
||||
missingamt,
|
||||
normaliseMixedAmount,
|
||||
nullamt,
|
||||
@ -183,13 +184,20 @@ showamountquantity :: Amount -> String
|
||||
showamountquantity (Amount (Commodity {decimalpoint=d,precision=p,separator=s,separatorpositions=spos}) q _) =
|
||||
punctuatenumber d s spos $ qstr
|
||||
where
|
||||
qstr -- | p == maxprecision && isint q = printf "%d" (round q::Integer)
|
||||
| p == maxprecision = printf "%f" q
|
||||
| otherwise = printf ("%."++show p++"f") q
|
||||
-- isint n = fromIntegral (round n) == n
|
||||
qstr -- | p == maxprecision && isint q = printf "%d" (round q::Integer)
|
||||
| p == maxprecisionwithpoint = printf "%f" q
|
||||
| p == maxprecision = chopdotzero $ printf "%f" q
|
||||
| otherwise = printf ("%."++show p++"f") q
|
||||
|
||||
chopdotzero str = reverse $ case reverse str of
|
||||
'0':'.':s -> s
|
||||
s -> s
|
||||
|
||||
-- | A special precision value meaning show all available digits.
|
||||
maxprecision = 999999
|
||||
maxprecision = 999998
|
||||
-- | Similar, forces display of a decimal point.
|
||||
maxprecisionwithpoint = 999999
|
||||
|
||||
-- | Replace a number string's decimal point with the specified character,
|
||||
-- and add the specified digit group separators.
|
||||
|
||||
@ -122,8 +122,10 @@ getPostings ctx accept historicalps enteredps = do
|
||||
| n > 1 = Just balancingamountstr
|
||||
| otherwise = Nothing
|
||||
where
|
||||
historicalamountstr = showMixedAmountWithPrecision maxprecision $ pamount $ fromJust bestmatch'
|
||||
balancingamountstr = showMixedAmountWithPrecision maxprecision $ negate $ sumMixedAmountsPreservingHighestPrecision $ map pamount enteredrealps
|
||||
-- force a decimal point in the output in case there's a
|
||||
-- digit group separator that would be mistaken for one
|
||||
historicalamountstr = showMixedAmountWithPrecision maxprecisionwithpoint $ pamount $ fromJust bestmatch'
|
||||
balancingamountstr = showMixedAmountWithPrecision maxprecisionwithpoint $ negate $ sumMixedAmountsPreservingHighestPrecision $ map pamount enteredrealps
|
||||
amountstr <- askFor (printf "amount %d" n) defaultamountstr validateamount
|
||||
let amount = fromparse $ runParser (someamount <|> return missingamt) ctx "" amountstr
|
||||
amount' = fromparse $ runParser (someamount <|> return missingamt) nullctx "" amountstr
|
||||
|
||||
@ -86,7 +86,7 @@ a
|
||||
b
|
||||
|
||||
.
|
||||
>>> /a +£1,000.0/
|
||||
>>> /a +£1,000.00/
|
||||
# 9. default amounts should not fail to balance due to precision
|
||||
bin/hledger -f nosuch.journal add
|
||||
<<<
|
||||
|
||||
Loading…
Reference in New Issue
Block a user