mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 10:17:35 +03:00
imp: print: show a disambiguating decimal mark when needed
Eg "1,000" (with , as a thousands separator and no decimal digits) is now displayed with a decimal mark: "1,000.". "1 000" (where space is a thousands separator) is less ambiguous, but we do the same thing (eg "1 000.") for consistency, and also to help disambiguate when forgetting to quote a numeric commodity symbol (eg "1234 0" where 1234 is a symbol that should have been in double quotes).
This commit is contained in:
parent
f620a3e0ea
commit
644635b918
@ -517,6 +517,10 @@ showAmount = wbUnpack . showAmountB noColour
|
||||
--
|
||||
-- * The special "missing" amount is displayed as the empty string.
|
||||
--
|
||||
-- * If an amount is showing digit group separators but no decimal places,
|
||||
-- we force showing a decimal mark (with nothing after it) to make
|
||||
-- it easier to parse correctly.
|
||||
--
|
||||
showAmountB :: AmountDisplayOpts -> Amount -> WideBuilder
|
||||
showAmountB _ Amount{acommodity="AUTO"} = mempty
|
||||
showAmountB opts a@Amount{astyle=style} =
|
||||
@ -565,6 +569,8 @@ showAmountDebug Amount{..} =
|
||||
|
||||
-- | Get a Text Builder for the string representation of the number part of of an amount,
|
||||
-- using the display settings from its commodity. Also returns the width of the number.
|
||||
-- A special case: if it is showing digit group separators but no decimal places,
|
||||
-- show a decimal mark (with nothing after it) to make it easier to parse correctly.
|
||||
showamountquantity :: Amount -> WideBuilder
|
||||
showamountquantity amt@Amount{astyle=AmountStyle{asdecimalmark=mdec, asdigitgroups=mgrps}} =
|
||||
signB <> intB <> fracB
|
||||
@ -578,10 +584,14 @@ showamountquantity amt@Amount{astyle=AmountStyle{asdecimalmark=mdec, asdigitgrou
|
||||
(intPart, fracPart) = T.splitAt intLen numtxtwithzero
|
||||
intB = applyDigitGroupStyle mgrps intLen $ if decplaces == 0 then numtxt else intPart
|
||||
signB = if mantissa < 0 then WideBuilder (TB.singleton '-') 1 else mempty
|
||||
fracB = if decplaces > 0
|
||||
fracB = if decplaces > 0 || isshowingdigitgroupseparator
|
||||
then WideBuilder (TB.singleton dec <> TB.fromText fracPart) (1 + fromIntegral decplaces)
|
||||
else mempty
|
||||
|
||||
isshowingdigitgroupseparator = case mgrps of
|
||||
Just (DigitGroups _ (rightmostgrplen:_)) -> intLen > fromIntegral rightmostgrplen
|
||||
_ -> False
|
||||
|
||||
-- | Given an integer as text, and its length, apply the given DigitGroupStyle,
|
||||
-- inserting digit group separators between digit groups where appropriate.
|
||||
-- Returns a Text builder and the number of digit group separators used.
|
||||
|
@ -73,3 +73,17 @@ $ hledger -f- print
|
||||
# (a) A1.234 @ B3.456 = A1.234 @ B3.456
|
||||
#
|
||||
# >=
|
||||
|
||||
# 3. When showing digit group marks, print always shows a decimal mark as well,
|
||||
# even when no decimal digits are shown.
|
||||
<
|
||||
decimal-mark .
|
||||
2023-01-01
|
||||
(a) 1,000
|
||||
|
||||
$ hledger -f- print
|
||||
2023-01-01
|
||||
(a) 1,000.
|
||||
|
||||
>=
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user