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,
|
isReallyZeroMixedAmountCost,
|
||||||
isZeroMixedAmount,
|
isZeroMixedAmount,
|
||||||
maxprecision,
|
maxprecision,
|
||||||
|
maxprecisionwithpoint,
|
||||||
missingamt,
|
missingamt,
|
||||||
normaliseMixedAmount,
|
normaliseMixedAmount,
|
||||||
nullamt,
|
nullamt,
|
||||||
@ -183,13 +184,20 @@ showamountquantity :: Amount -> String
|
|||||||
showamountquantity (Amount (Commodity {decimalpoint=d,precision=p,separator=s,separatorpositions=spos}) q _) =
|
showamountquantity (Amount (Commodity {decimalpoint=d,precision=p,separator=s,separatorpositions=spos}) q _) =
|
||||||
punctuatenumber d s spos $ qstr
|
punctuatenumber d s spos $ qstr
|
||||||
where
|
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
|
-- 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.
|
-- | 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,
|
-- | Replace a number string's decimal point with the specified character,
|
||||||
-- and add the specified digit group separators.
|
-- and add the specified digit group separators.
|
||||||
|
|||||||
@ -122,8 +122,10 @@ getPostings ctx accept historicalps enteredps = do
|
|||||||
| n > 1 = Just balancingamountstr
|
| n > 1 = Just balancingamountstr
|
||||||
| otherwise = Nothing
|
| otherwise = Nothing
|
||||||
where
|
where
|
||||||
historicalamountstr = showMixedAmountWithPrecision maxprecision $ pamount $ fromJust bestmatch'
|
-- force a decimal point in the output in case there's a
|
||||||
balancingamountstr = showMixedAmountWithPrecision maxprecision $ negate $ sumMixedAmountsPreservingHighestPrecision $ map pamount enteredrealps
|
-- 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
|
amountstr <- askFor (printf "amount %d" n) defaultamountstr validateamount
|
||||||
let amount = fromparse $ runParser (someamount <|> return missingamt) ctx "" amountstr
|
let amount = fromparse $ runParser (someamount <|> return missingamt) ctx "" amountstr
|
||||||
amount' = fromparse $ runParser (someamount <|> return missingamt) nullctx "" amountstr
|
amount' = fromparse $ runParser (someamount <|> return missingamt) nullctx "" amountstr
|
||||||
|
|||||||
@ -86,7 +86,7 @@ a
|
|||||||
b
|
b
|
||||||
|
|
||||||
.
|
.
|
||||||
>>> /a +£1,000.0/
|
>>> /a +£1,000.00/
|
||||||
# 9. default amounts should not fail to balance due to precision
|
# 9. default amounts should not fail to balance due to precision
|
||||||
bin/hledger -f nosuch.journal add
|
bin/hledger -f nosuch.journal add
|
||||||
<<<
|
<<<
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user