Hledger.Data.Amount

hledger-lib-1.41: A library providing the core functionality of hledger

Safe Haskell | None
Language | Haskell2010

Hledger.Data.Amount

Contents

- Commodity
- Amount
  - arithmetic
  - styles
  - rendering
- MixedAmount
  - arithmetic
  - styles
  - rendering
- misc.
- Orphan instances

Description

A simple `Amount` is some quantity of money, shares, or anything else. It has a (possibly null) `CommoditySymbol` and a numeric quantity:

      $1
      £-50
      EUR 3.44
      GOOG 500
      1.5h
      90 apples
      0

It may also have an `AmountCost`, representing this amount's per-unit or total cost in a different commodity. If present, this is rendered like so:

      EUR 2 @ $1.50  (unit cost)
      EUR 2 @@ $3   (total cost)

A `MixedAmount` is zero or more simple amounts, so can represent multiple commodities; this is the type most often used:

      0
      $50 + EUR 3
      16h + $13.55 + AAPL 500 + 6 oranges

A mixed amount is always "normalised", it has no more than one amount in each commodity and cost. When calling `amounts` it will have no zero amounts, or just a single zero amount and no other amounts.

Limited arithmetic with simple and mixed amounts is supported, best used with similar amounts since it mostly ignores costss and commodity exchange rates.

Synopsis

- showCommoditySymbol :: Text -> Text
- isNonsimpleCommodityChar :: Char -> Bool
- quoteCommoditySymbolIfNeeded :: Text -> Text
- nullamt :: Amount
- missingamt :: Amount
- num :: Quantity -> Amount
- usd :: DecimalRaw Integer -> Amount
- eur :: DecimalRaw Integer -> Amount
- gbp :: DecimalRaw Integer -> Amount
- per :: Quantity -> Amount
- hrs :: Quantity -> Amount
- at :: Amount -> Amount -> Amount
- (@@) :: Amount -> Amount -> Amount
- amountWithCommodity :: CommoditySymbol -> Amount -> Amount
- amountCost :: Amount -> Amount
- amountIsZero :: Amount -> Bool
- amountLooksZero :: Amount -> Bool
- divideAmount :: Quantity -> Amount -> Amount
- multiplyAmount :: Quantity -> Amount -> Amount
- invertAmount :: Amount -> Amount
- amountstyle :: AmountStyle
- canonicaliseAmount :: Map CommoditySymbol AmountStyle -> Amount -> Amount
- styleAmount :: Map CommoditySymbol AmountStyle -> Amount -> Amount
- amountSetStyles :: Map CommoditySymbol AmountStyle -> Amount -> Amount
- amountStyleSetRounding :: Rounding -> AmountStyle -> AmountStyle
- amountStylesSetRounding :: Rounding -> Map CommoditySymbol AmountStyle -> Map CommoditySymbol AmountStyle
- amountUnstyled :: Amount -> Amount
- data AmountFormat = AmountFormat {
  - displayCommodity :: Bool
  - displayZeroCommodity :: Bool
  - displayCommodityOrder :: Maybe [CommoditySymbol]
  - displayDigitGroups :: Bool
  - displayForceDecimalMark :: Bool
  - displayOneLine :: Bool
  - displayMinWidth :: Maybe Int
  - displayMaxWidth :: Maybe Int
  - displayCost :: Bool
  - displayColour :: Bool
  - displayQuotes :: Bool
  }
- defaultFmt :: AmountFormat
- fullZeroFmt :: AmountFormat
- noCostFmt :: AmountFormat
- oneLineFmt :: AmountFormat
- oneLineNoCostFmt :: AmountFormat
- machineFmt :: AmountFormat
- showAmount :: Amount -> String
- showAmountWith :: AmountFormat -> Amount -> String
- showAmountB :: AmountFormat -> Amount -> WideBuilder
- showAmountCostB :: AmountFormat -> Amount -> WideBuilder
- cshowAmount :: Amount -> String
- showAmountWithZeroCommodity :: Amount -> String
- showAmountDebug :: Amount -> String
- showAmountWithoutCost :: Amount -> String
- amountSetPrecision :: AmountPrecision -> Amount -> Amount
- amountSetPrecisionMin :: Word8 -> Amount -> Amount
- amountSetPrecisionMax :: Word8 -> Amount -> Amount
- withPrecision :: Amount -> AmountPrecision -> Amount
- amountSetFullPrecision :: Amount -> Amount
- amountSetFullPrecisionUpTo :: Maybe Word8 -> Amount -> Amount
- amountInternalPrecision :: Amount -> Word8
- amountDisplayPrecision :: Amount -> Word8
- defaultMaxPrecision :: Word8
- setAmountInternalPrecision :: Word8 -> Amount -> Amount
- withInternalPrecision :: Amount -> Word8 -> Amount
- setAmountDecimalPoint :: Maybe Char -> Amount -> Amount
- withDecimalPoint :: Amount -> Maybe Char -> Amount
- amountStripCost :: Amount -> Amount
- nullmixedamt :: MixedAmount
- missingmixedamt :: MixedAmount
- isMissingMixedAmount :: MixedAmount -> Bool
- mixed :: Foldable t => t Amount -> MixedAmount
- mixedAmount :: Amount -> MixedAmount
- maAddAmount :: MixedAmount -> Amount -> MixedAmount
- maAddAmounts :: Foldable t => MixedAmount -> t Amount -> MixedAmount
- amounts :: MixedAmount -> [Amount]
- amountsRaw :: MixedAmount -> [Amount]
- amountsPreservingZeros :: MixedAmount -> [Amount]
- maCommodities :: MixedAmount -> Set CommoditySymbol
- filterMixedAmount :: (Amount -> Bool) -> MixedAmount -> MixedAmount
- filterMixedAmountByCommodity :: CommoditySymbol -> MixedAmount -> MixedAmount
- mapMixedAmount :: (Amount -> Amount) -> MixedAmount -> MixedAmount
- unifyMixedAmount :: MixedAmount -> Maybe Amount
- mixedAmountStripCosts :: MixedAmount -> MixedAmount
- mixedAmountCost :: MixedAmount -> MixedAmount
- maNegate :: MixedAmount -> MixedAmount
- maPlus :: MixedAmount -> MixedAmount -> MixedAmount
- maMinus :: MixedAmount -> MixedAmount -> MixedAmount
- maSum :: Foldable t => t MixedAmount -> MixedAmount
- divideMixedAmount :: Quantity -> MixedAmount -> MixedAmount
- multiplyMixedAmount :: Quantity -> MixedAmount -> MixedAmount
- averageMixedAmounts :: [MixedAmount] -> MixedAmount
- isNegativeAmount :: Amount -> Bool
- isNegativeMixedAmount :: MixedAmount -> Maybe Bool
- mixedAmountIsZero :: MixedAmount -> Bool
- maIsZero :: MixedAmount -> Bool
- maIsNonZero :: MixedAmount -> Bool
- mixedAmountLooksZero :: MixedAmount -> Bool
- canonicaliseMixedAmount :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
- styleMixedAmount :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
- mixedAmountSetStyles :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount
- mixedAmountUnstyled :: MixedAmount -> MixedAmount
- showMixedAmount :: MixedAmount -> String
- showMixedAmountWith :: AmountFormat -> MixedAmount -> String
- showMixedAmountOneLine :: MixedAmount -> String
- showMixedAmountDebug :: MixedAmount -> String
- showMixedAmountWithoutCost :: Bool -> MixedAmount -> String
- showMixedAmountOneLineWithoutCost :: Bool -> MixedAmount -> String
- showMixedAmountElided :: Int -> Bool -> MixedAmount -> String
- showMixedAmountWithZeroCommodity :: MixedAmount -> String
- showMixedAmountB :: AmountFormat -> MixedAmount -> WideBuilder
- showMixedAmountLinesB :: AmountFormat -> MixedAmount -> [WideBuilder]
- showMixedAmountLinesPartsB :: AmountFormat -> MixedAmount -> [(WideBuilder, Amount)]
- wbToText :: WideBuilder -> Text
- wbUnpack :: WideBuilder -> String
- mixedAmountSetPrecision :: AmountPrecision -> MixedAmount -> MixedAmount
- mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount
- mixedAmountSetFullPrecisionUpTo :: Maybe Word8 -> MixedAmount -> MixedAmount
- mixedAmountSetPrecisionMin :: Word8 -> MixedAmount -> MixedAmount
- mixedAmountSetPrecisionMax :: Word8 -> MixedAmount -> MixedAmount
- tests_Amount :: TestTree

# Commodity

showCommoditySymbol :: Text -> Text #

Show space-containing commodity symbols quoted, as they are in a journal.

isNonsimpleCommodityChar :: Char -> Bool #

quoteCommoditySymbolIfNeeded :: Text -> Text #

# Amount

## arithmetic

nullamt :: Amount #

The empty simple amount - a zero with no commodity symbol or cost and the default amount display style.

missingamt :: Amount #

A special amount used as a marker, meaning "no explicit amount provided here, infer it when needed". It is nullamt with commodity symbol AUTO.

num :: Quantity -> Amount #

usd :: DecimalRaw Integer -> Amount #

eur :: DecimalRaw Integer -> Amount #

gbp :: DecimalRaw Integer -> Amount #

per :: Quantity -> Amount #

hrs :: Quantity -> Amount #

at :: Amount -> Amount -> Amount #

(@@) :: Amount -> Amount -> Amount #

amountWithCommodity :: CommoditySymbol -> Amount -> Amount #

Convert an amount to the specified commodity, ignoring and discarding any costs and assuming an exchange rate of 1.

amountCost :: Amount -> Amount #

Convert a amount to its total cost in another commodity, using its attached cost amount if it has one. Notes:

- cost amounts must be MixedAmounts with exactly one component Amount (or there will be a runtime error XXX)
- cost amounts should be positive in the Journal (though this is currently not enforced)

amountIsZero :: Amount -> Bool #

Is this Amount (and its total cost, if it has one) exactly zero, ignoring its display precision ?

amountLooksZero :: Amount -> Bool #

Do this Amount and (and its total cost, if it has one) appear to be zero when rendered with its display precision ? The display precision should usually have a specific value here; if unset, it will be treated like NaturalPrecision.

divideAmount :: Quantity -> Amount -> Amount #

Divide an amount's quantity (and total cost, if any) by some number.

multiplyAmount :: Quantity -> Amount -> Amount #

Multiply an amount's quantity (and its total cost, if it has one) by a constant.

invertAmount :: Amount -> Amount #

Invert an amount (replace its quantity q with 1/q). (Its cost if any is not changed, currently.)

## styles

amountstyle :: AmountStyle #

Default amount style

canonicaliseAmount :: Map CommoditySymbol AmountStyle -> Amount -> Amount #

Deprecated: please use styleAmounts instead

styleAmount :: Map CommoditySymbol AmountStyle -> Amount -> Amount #

Deprecated: please use styleAmounts instead

amountSetStyles :: Map CommoditySymbol AmountStyle -> Amount -> Amount #

Deprecated: please use styleAmounts instead

amountStyleSetRounding :: Rounding -> AmountStyle -> AmountStyle #

Set this amount style's rounding strategy when it is being applied to amounts.

amountStylesSetRounding :: Rounding -> Map CommoditySymbol AmountStyle -> Map CommoditySymbol AmountStyle #

Set these amount styles' rounding strategy when they are being applied to amounts.

amountUnstyled :: Amount -> Amount #

Reset this amount's display style to the default.

## rendering

data AmountFormat #

Formatting options available when displaying Amounts and MixedAmounts. Similar to AmountStyle but lower level, not attached to amounts or commodities, and can override it in some ways. See also hledger manual > "Amount formatting, parseability", which speaks of human, hledger, and machine output.

Constructors

AmountFormat |
Fields displayCommodity :: Bool Whether to display commodity symbols. displayZeroCommodity :: Bool Whether to display commodity symbols for zero Amounts. displayCommodityOrder :: Maybe [CommoditySymbol] For a MixedAmount, an optional order in which to display the commodities. Also, causes 0s to be generated for any commodities which are not present (important for tabular reports). displayDigitGroups :: Bool Whether to display digit group marks (eg thousands separators) displayForceDecimalMark :: Bool Whether to add a trailing decimal mark when there are no decimal digits and there are digit group marks, to disambiguate displayOneLine :: Bool Whether to display on one line. displayMinWidth :: Maybe Int Minimum width to pad to displayMaxWidth :: Maybe Int Maximum width to clip to displayCost :: Bool Whether to display Amounts' costs. displayColour :: Bool Whether to ansi-colourise negative Amounts. displayQuotes :: Bool Whether to enclose complex symbols in quotes (normally true)

#### Instances

Instances details

Default AmountFormat # | By default, display amounts using `defaultFmt` amount display options.
Instance details Defined in Hledger.Data.Amount Methods def :: AmountFormat #
Show AmountFormat # |
Instance details Defined in Hledger.Data.Amount Methods showsPrec :: Int -> AmountFormat -> ShowS # show :: AmountFormat -> String # showList :: [AmountFormat] -> ShowS #

defaultFmt :: AmountFormat #

Display amounts without colour, and with various other defaults.

fullZeroFmt :: AmountFormat #

Like defaultFmt but show zero amounts with commodity symbol and styling, like non-zero amounts.

noCostFmt :: AmountFormat #

Like defaultFmt but don't show costs.

oneLineFmt :: AmountFormat #

Like defaultFmt but display all amounts on one line.

oneLineNoCostFmt :: AmountFormat #

Like noCostFmt but display all amounts on one line.

machineFmt :: AmountFormat #

A (slightly more) machine-readable amount format; like oneLineNoCostFmt but don't show digit group marks.

showAmount :: Amount -> String #

Render an amount using its display style and the default amount format. Zero-equivalent amounts are shown as just "0". The special "missing" amount is shown as the empty string.

showAmountWith :: AmountFormat -> Amount -> String #

Like showAmount but uses the given amount format.

showAmountB :: AmountFormat -> Amount -> WideBuilder #

Render an amount using its display style and the given amount format, as a builder for efficiency. (This can be converted to a Text with wbToText or to a String with wbUnpack). The special "missing" amount is displayed as the empty string.

showAmountCostB :: AmountFormat -> Amount -> WideBuilder #

cshowAmount :: Amount -> String #

Colour version. For a negative amount, adds ANSI codes to change the colour, currently to hard-coded red.

    cshowAmount = wbUnpack . showAmountB def{displayColour=True}

showAmountWithZeroCommodity :: Amount -> String #

Like showAmount, but show a zero amount's commodity if it has one.

    showAmountWithZeroCommodity = wbUnpack . showAmountB defaultFmt{displayZeryCommodity=True}

showAmountDebug :: Amount -> String #

Get a string representation of an amount for debugging, appropriate to the current debug level. 9 shows maximum detail.

showAmountWithoutCost :: Amount -> String #

Get the string representation of an amount, without any @ cost.

    showAmountWithoutCost = wbUnpack . showAmountB noCostFmt

amountSetPrecision :: AmountPrecision -> Amount -> Amount #

Set an amount's display precision.

amountSetPrecisionMin :: Word8 -> Amount -> Amount #

Ensure an amount's display precision is at least the given minimum precision. Always sets an explicit Precision.

amountSetPrecisionMax :: Word8 -> Amount -> Amount #

Ensure an amount's display precision is at most the given maximum precision. Always sets an explicit Precision.

withPrecision :: Amount -> AmountPrecision -> Amount #

Set an amount's display precision, flipped.

amountSetFullPrecision :: Amount -> Amount #

Increase an amount's display precision, if needed, to enough decimal places to show it exactly (showing all significant decimal digits, without trailing zeros). If the amount's display precision is unset, it will be treated as precision 0.

amountSetFullPrecisionUpTo :: Maybe Word8 -> Amount -> Amount #

We often want to display "infinite decimal" amounts rounded to some readable number of digits, while still displaying amounts with a large but "non infinite" number of decimal digits (eg 10 or 100 or 200 digits) in full. This helper is like amountSetFullPrecision, but with some refinements:

1. A maximum display precision can be specified, setting a hard upper limit.
2. If no limit is specified, and the internal precision is the maximum (255), indicating an infinite decimal, display precision is set to a smaller default (8).

This function always sets an explicit display precision (ie, Precision n).

amountInternalPrecision :: Amount -> Word8 #

How many internal decimal digits are stored for this amount ?

amountDisplayPrecision :: Amount -> Word8 #

How many decimal digits will be displayed for this amount ?

defaultMaxPrecision :: Word8 #

The fallback display precision used when showing amounts representing an infinite decimal.

setAmountInternalPrecision :: Word8 -> Amount -> Amount #

Set an amount's internal decimal precision as well as its display precision. This rounds or pads its Decimal quantity to the specified number of decimal places. Rounding is done with Data.Decimal's default roundTo function: "If the value ends in 5 then it is rounded to the nearest even value (Banker's Rounding)".

withInternalPrecision :: Amount -> Word8 -> Amount #

setAmountInternalPrecision with arguments flipped.

setAmountDecimalPoint :: Maybe Char -> Amount -> Amount #

Set (or clear) an amount's display decimal point.

withDecimalPoint :: Amount -> Maybe Char -> Amount #

Set (or clear) an amount's display decimal point, flipped.

amountStripCost :: Amount -> Amount #

Strip all costs from an Amount

# MixedAmount

nullmixedamt :: MixedAmount #

The empty mixed amount.

missingmixedamt :: MixedAmount #

A special mixed amount used as a marker, meaning "no explicit amount provided here, infer it when needed".

isMissingMixedAmount :: MixedAmount -> Bool #

Does this MixedAmount include the "missing amount" marker ? Note: currently does not test for equality with missingmixedamt, instead it looks for missingamt among the Amounts. missingamt should always be alone, but detect it even if not.

mixed :: Foldable t => t Amount -> MixedAmount #

Convert amounts in various commodities into a mixed amount.

mixedAmount :: Amount -> MixedAmount #

Create a MixedAmount from a single Amount.

maAddAmount :: MixedAmount -> Amount -> MixedAmount #

Add an Amount to a MixedAmount, normalising the result. Amounts with different costs are kept separate.

maAddAmounts :: Foldable t => MixedAmount -> t Amount -> MixedAmount #

Add a collection of Amounts to a MixedAmount, normalising the result. Amounts with different costs are kept separate.

amounts :: MixedAmount -> [Amount] #

Get a mixed amount's component amounts, with some cleanups. The following descriptions are old and possibly wrong:

- amounts in the same commodity are combined unless they have different costs or total costs
- multiple zero amounts, all with the same non-null commodity, are replaced by just the last of them, preserving the commodity and amount style (all but the last zero amount are discarded)
- multiple zero amounts with multiple commodities, or no commodities, are replaced by one commodity-less zero amount
- an empty amount list is replaced by one commodity-less zero amount
- the special "missing" mixed amount remains unchanged

amountsRaw :: MixedAmount -> [Amount] #

Get a mixed amount's component amounts without normalising zero and missing amounts. This is used for JSON serialisation, so the order is important. In particular, we want the Amounts given in the order of the MixedAmountKeys, i.e. lexicographically first by commodity, then by cost commodity, then by unit cost from most negative to most positive.

amountsPreservingZeros :: MixedAmount -> [Amount] #

Get a mixed amount's component amounts, with some cleanups. This is a new version of `amounts`, with updated descriptions and optimised for `print` to show commodityful zeros.

- If it contains the "missing amount" marker, only that is returned (discarding any additional amounts).
- Or if it contains any non-zero amounts, only those are returned (discarding any zeroes).
- Or if it contains any zero amounts (possibly more than one, possibly in different commodities), all of those are returned.
- Otherwise the null amount is returned.

maCommodities :: MixedAmount -> Set CommoditySymbol #

Get this mixed amount's commodities as a set. Returns an empty set if there are no amounts.

filterMixedAmount :: (Amount -> Bool) -> MixedAmount -> MixedAmount #

Filter a mixed amount's component amounts by a predicate.

filterMixedAmountByCommodity :: CommoditySymbol -> MixedAmount -> MixedAmount #

Return an unnormalised MixedAmount containing just the amounts in the requested commodity from the original mixed amount.

The result will contain at least one Amount of the requested commodity, even if the original mixed amount did not (with quantity zero in that case, and this would be discarded when the mixed amount is next normalised).

The result can contain more than one Amount of the requested commodity, eg because there were several with different costs, or simply because the original mixed amount was was unnormalised.

mapMixedAmount :: (Amount -> Amount) -> MixedAmount -> MixedAmount #

Apply a transform to a mixed amount's component `Amount`s.

unifyMixedAmount :: MixedAmount -> Maybe Amount #

Unify a MixedAmount to a single commodity value if possible. This consolidates amounts of the same commodity and discards zero amounts; but this one insists on simplifying to a single commodity, and will return Nothing if this is not possible.

mixedAmountStripCosts :: MixedAmount -> MixedAmount #

Remove all costs from a MixedAmount.

## arithmetic

mixedAmountCost :: MixedAmount -> MixedAmount #

Convert all component amounts to cost where possible (see amountCost).

maNegate :: MixedAmount -> MixedAmount #

Negate mixed amount's quantities (and total costs, if any).

maPlus :: MixedAmount -> MixedAmount -> MixedAmount #

Sum two MixedAmount, keeping the cost of the first if any. Amounts with different costs are kept separate (since 2021).

maMinus :: MixedAmount -> MixedAmount -> MixedAmount #

Subtract a MixedAmount from another. Amounts with different costs are kept separate.

maSum :: Foldable t => t MixedAmount -> MixedAmount #

Sum a collection of MixedAmounts. Amounts with different costs are kept separate.

divideMixedAmount :: Quantity -> MixedAmount -> MixedAmount #

Divide a mixed amount's quantities (and total costs, if any) by a constant.

multiplyMixedAmount :: Quantity -> MixedAmount -> MixedAmount #

Multiply a mixed amount's quantities (and total costs, if any) by a constant.

averageMixedAmounts :: [MixedAmount] -> MixedAmount #

Calculate the average of some mixed amounts.

isNegativeAmount :: Amount -> Bool #

Is this amount negative ? The cost is ignored.

isNegativeMixedAmount :: MixedAmount -> Maybe Bool #

Is this mixed amount negative, if we can tell that unambiguously? Ie when normalised, are all individual commodity amounts negative ?

mixedAmountIsZero :: MixedAmount -> Bool #

Is this mixed amount exactly zero, ignoring its display precision? See amountIsZero.

maIsZero :: MixedAmount -> Bool #

Is this mixed amount exactly zero, ignoring its display precision?

A convenient alias for mixedAmountIsZero.

maIsNonZero :: MixedAmount -> Bool #

Is this mixed amount non-zero, ignoring its display precision?

A convenient alias for not . mixedAmountIsZero.

mixedAmountLooksZero :: MixedAmount -> Bool #

Does this mixed amount appear to be zero when rendered with its display precision? See amountLooksZero.

## styles

canonicaliseMixedAmount :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount #

Deprecated: please use mixedAmountSetStyle False (or styleAmounts) instead

styleMixedAmount :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount #

Deprecated: please use styleAmounts instead

Given a map of standard commodity display styles, find and apply the appropriate style to each individual amount.

mixedAmountSetStyles :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount #

Deprecated: please use styleAmounts instead

mixedAmountUnstyled :: MixedAmount -> MixedAmount #

Reset each individual amount's display style to the default.

## rendering

showMixedAmount :: MixedAmount -> String #

Render a mixed amount using its amount display styles and the default amount format, after normalising it (to at most one amount in each of its commodities). See showMixedAmountB for special cases.

showMixedAmountWith :: AmountFormat -> MixedAmount -> String #

Like showMixedAmount but uses the given amount format. See showMixedAmountB for special cases.

showMixedAmountOneLine :: MixedAmount -> String #

Get the one-line string representation of a mixed amount (also showing any costs). See showMixedAmountB for special cases.

showMixedAmountDebug :: MixedAmount -> String #

Get an unambiguous string representation of a mixed amount for debugging.

showMixedAmountWithoutCost :: Bool -> MixedAmount -> String #

Get the string representation of a mixed amount, without showing any costs. With a True argument, adds ANSI codes to show negative amounts in red. See showMixedAmountB for special cases.

showMixedAmountOneLineWithoutCost :: Bool -> MixedAmount -> String #

Get the one-line string representation of a mixed amount, but without any @ costs. With a True argument, adds ANSI codes to show negative amounts in red. See showMixedAmountB for special cases.

showMixedAmountElided :: Int -> Bool -> MixedAmount -> String #

Like showMixedAmountOneLineWithoutCost, but show at most the given width, with an elision indicator if there are more. With a True argument, adds ANSI codes to show negative amounts in red. See showMixedAmountB for special cases.

showMixedAmountWithZeroCommodity :: MixedAmount -> String #

Like showMixedAmount, but zero amounts are shown with their commodity if they have one. See showMixedAmountB for special cases.

showMixedAmountB :: AmountFormat -> MixedAmount -> WideBuilder #

Render a mixed amount using its amount display styles and the given amount format, as a builder for efficiency. (This can be converted to a Text with wbToText or to a String with wbUnpack).

Warning: this (and its showMixedAmount aliases above) basically assumes amounts have no costs. It can show misleading costs or not show costs which are there.

If a maximum width is given then:

- If displayed on one line, it will display as many Amounts as can fit in the given width, and further Amounts will be elided. There will always be at least one amount displayed, even if this will exceed the requested maximum width.
- If displayed on multiple lines, any Amounts longer than the maximum width will be elided.

Zero-equivalent amounts are shown as just "0".

The special "missing" amount is shown as the empty string (?).

showMixedAmountLinesB :: AmountFormat -> MixedAmount -> [WideBuilder] #

Helper for showMixedAmountB (and postingAsLines, ...) to show a list of Amounts on multiple lines. This returns the list of WideBuilders: one for each Amount, and padded/elided to the appropriate width. This does not honour displayOneLine; all amounts will be displayed as if displayOneLine were False.

showMixedAmountLinesPartsB :: AmountFormat -> MixedAmount -> [(WideBuilder, Amount)] #

Like `showMixedAmountLinesB` but also returns the amounts associated with each text builder.

wbToText :: WideBuilder -> Text #

Convert a WideBuilder to a strict Text.

wbUnpack :: WideBuilder -> String #

Convert a WideBuilder to a String.

mixedAmountSetPrecision :: AmountPrecision -> MixedAmount -> MixedAmount #

Set the display precision in the amount's commodities.

mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount #

In each component amount, increase the display precision sufficiently to render it exactly (showing all significant decimal digits).

mixedAmountSetFullPrecisionUpTo :: Maybe Word8 -> MixedAmount -> MixedAmount #

In each component amount, increase the display precision sufficiently to render it exactly if possible, but not more than the given max precision, and if no max precision is given and the amount has infinite decimals, limit display precision to a hard-coded smaller number (8). See amountSetFullPrecisionUpTo.

mixedAmountSetPrecisionMin :: Word8 -> MixedAmount -> MixedAmount #

In each component amount, ensure the display precision is at least the given value. Makes all amounts have an explicit Precision.

mixedAmountSetPrecisionMax :: Word8 -> MixedAmount -> MixedAmount #

In each component amount, ensure the display precision is at most the given value. Makes all amounts have an explicit Precision.

# misc.

tests_Amount :: TestTree #

# Orphan instances

Monoid MixedAmount # |
Instance details Methods mempty :: MixedAmount # mappend :: MixedAmount -> MixedAmount -> MixedAmount # mconcat :: [MixedAmount] -> MixedAmount #
Semigroup MixedAmount # |
Instance details Methods (<>) :: MixedAmount -> MixedAmount -> MixedAmount # sconcat :: NonEmpty MixedAmount -> MixedAmount # stimes :: Integral b => b -> MixedAmount -> MixedAmount #
Num Amount # |
Instance details Methods (+) :: Amount -> Amount -> Amount # (-) :: Amount -> Amount -> Amount # (*) :: Amount -> Amount -> Amount # negate :: Amount -> Amount # abs :: Amount -> Amount # signum :: Amount -> Amount # fromInteger :: Integer -> Amount #
Num MixedAmount # |
Instance details Methods (+) :: MixedAmount -> MixedAmount -> MixedAmount # (-) :: MixedAmount -> MixedAmount -> MixedAmount # (*) :: MixedAmount -> MixedAmount -> MixedAmount # negate :: MixedAmount -> MixedAmount # abs :: MixedAmount -> MixedAmount # signum :: MixedAmount -> MixedAmount # fromInteger :: Integer -> MixedAmount #
HasAmounts Account # |
Instance details Methods styleAmounts :: Map CommoditySymbol AmountStyle -> Account -> Account #
HasAmounts Amount # |
Instance details Methods styleAmounts :: Map CommoditySymbol AmountStyle -> Amount -> Amount #
HasAmounts MixedAmount # |
Instance details Methods styleAmounts :: Map CommoditySymbol AmountStyle -> MixedAmount -> MixedAmount #