dev: amounts: cleanups
This commit is contained in:
parent
d3cc31780a
commit
9b15d34f9c
@ -197,6 +197,7 @@ quoteCommoditySymbolIfNeeded s
|
|||||||
|
|
||||||
|
|
||||||
-- | Options for the display of Amount and MixedAmount.
|
-- | Options for the display of Amount and MixedAmount.
|
||||||
|
-- (See also Types.AmountStyle)
|
||||||
data AmountDisplayOpts = AmountDisplayOpts
|
data AmountDisplayOpts = AmountDisplayOpts
|
||||||
{ displayPrice :: Bool -- ^ Whether to display the Price of an Amount.
|
{ displayPrice :: Bool -- ^ Whether to display the Price of an Amount.
|
||||||
, displayZeroCommodity :: Bool -- ^ If the Amount rounds to 0, whether to display its commodity string.
|
, displayZeroCommodity :: Bool -- ^ If the Amount rounds to 0, whether to display its commodity string.
|
||||||
@ -420,7 +421,7 @@ showAmountPriceDebug (Just (TotalPrice pa)) = " @@ " ++ showAmountDebug pa
|
|||||||
-- | Given a map of standard commodity display styles, apply the
|
-- | Given a map of standard commodity display styles, apply the
|
||||||
-- appropriate one to this amount. If there's no standard style for
|
-- appropriate one to this amount. If there's no standard style for
|
||||||
-- this amount's commodity, return the amount unchanged.
|
-- this amount's commodity, return the amount unchanged.
|
||||||
-- Also apply the style to the price (except for precision)
|
-- Also apply the style, except for precision, to the cost.
|
||||||
styleAmount :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
|
styleAmount :: M.Map CommoditySymbol AmountStyle -> Amount -> Amount
|
||||||
styleAmount styles a = styledAmount{aprice = stylePrice styles (aprice styledAmount)}
|
styleAmount styles a = styledAmount{aprice = stylePrice styles (aprice styledAmount)}
|
||||||
where
|
where
|
||||||
@ -806,8 +807,8 @@ mixedAmountCost (Mixed ma) =
|
|||||||
-- where a' = mixedAmountStripPrices a
|
-- where a' = mixedAmountStripPrices a
|
||||||
-- b' = mixedAmountStripPrices b
|
-- b' = mixedAmountStripPrices b
|
||||||
|
|
||||||
-- | Given a map of standard commodity display styles, apply the
|
-- | Given a map of standard commodity display styles, find and apply
|
||||||
-- appropriate one to each individual amount.
|
-- the appropriate style to each individual amount.
|
||||||
styleMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
styleMixedAmount :: M.Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
|
||||||
styleMixedAmount styles = mapMixedAmountUnsafe (styleAmount styles)
|
styleMixedAmount styles = mapMixedAmountUnsafe (styleAmount styles)
|
||||||
|
|
||||||
|
|||||||
@ -250,6 +250,7 @@ data AmountPrice = UnitPrice !Amount | TotalPrice !Amount
|
|||||||
deriving (Eq,Ord,Generic,Show)
|
deriving (Eq,Ord,Generic,Show)
|
||||||
|
|
||||||
-- | Display style for an amount.
|
-- | Display style for an amount.
|
||||||
|
-- (See also Amount.AmountDisplayOpts)
|
||||||
data AmountStyle = AmountStyle {
|
data AmountStyle = AmountStyle {
|
||||||
ascommodityside :: !Side, -- ^ does the symbol appear on the left or the right ?
|
ascommodityside :: !Side, -- ^ does the symbol appear on the left or the right ?
|
||||||
ascommodityspaced :: !Bool, -- ^ space between symbol and quantity ?
|
ascommodityspaced :: !Bool, -- ^ space between symbol and quantity ?
|
||||||
@ -270,9 +271,10 @@ instance Show AmountStyle where
|
|||||||
|
|
||||||
-- | The "display precision" for a hledger amount, by which we mean
|
-- | The "display precision" for a hledger amount, by which we mean
|
||||||
-- the number of decimal digits to display to the right of the decimal mark.
|
-- the number of decimal digits to display to the right of the decimal mark.
|
||||||
-- This can be from 0 to 255 digits (the maximum supported by the Decimal library),
|
data AmountPrecision =
|
||||||
-- or NaturalPrecision meaning "show all significant decimal digits".
|
Precision !Word8 -- ^ show this many decimal digits (0..255)
|
||||||
data AmountPrecision = Precision !Word8 | NaturalPrecision deriving (Eq,Ord,Read,Show,Generic)
|
| NaturalPrecision -- ^ show all significant decimal digits stored internally
|
||||||
|
deriving (Eq,Ord,Read,Show,Generic)
|
||||||
|
|
||||||
-- | A style for displaying digit groups in the integer part of a
|
-- | A style for displaying digit groups in the integer part of a
|
||||||
-- floating point number. It consists of the character used to
|
-- floating point number. It consists of the character used to
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user