hledger-lib
Safe HaskellNone
LanguageGHC2021

Hledger.Data.Amount

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

Commodity

showCommoditySymbol :: Text -> Text Source #

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

Amount

arithmetic

nullamt :: Amount Source #

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

missingamt :: Amount Source #

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

usd :: DecimalRaw Integer -> Amount Source #

eur :: DecimalRaw Integer -> Amount Source #

gbp :: DecimalRaw Integer -> Amount Source #

amountWithCommodity :: CommoditySymbol -> Amount -> Amount Source #

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

amountCost :: Amount -> Amount Source #

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)

amountCostBasis :: Amount -> Amount Source #

Convert an Amount to its cost basis when it has a cost basis annotation with a cost (as lot postings do after lot processing), otherwise to its transacted cost as amountCost does. This is what -B/--value=cost reports: for a lot disposal it gives what the disposed units cost, not the proceeds.

amountSetCostToBasis :: Amount -> Amount Source #

If this amount has a cost basis with a known per-unit cost, replace its transacted cost with that basis cost, so that amountCost, and sums at cost (which merge amounts by commodity and transacted cost, dropping differing bases), reflect the cost basis. Other amounts are unchanged.

amountIsZero :: Amount -> Bool Source #

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

amountLooksZero :: Amount -> Bool Source #

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.

amountSetQuantity :: Quantity -> Amount -> Amount Source #

Replace an amount's quantity, resetting display precision to NaturalPrecision. This is the safe way to set a new quantity that may have different decimal places than the original — NaturalPrecision ensures the exact value is always displayed. Commodity styles will override the precision at rendering time.

divideAmount :: Quantity -> Amount -> Amount Source #

Divide an amount's quantity (and total cost, if any) by some number. Returns the amount unchanged when the divisor is zero.

divideAmountAndUpdatePrecision :: Quantity -> Amount -> Amount Source #

Like divideAmount, but sets the display precision to exactly the number of significant decimal digits in the quotient (capped at defaultMaxDisplayPrecision), so the quotient's digits stay visible without adding trailing zeros. Use this when the quotient is intended for display in a journal entry (eg per-unit cost derived from a total cost); for aggregate report cells, prefer divideAmount to keep the report's chosen precision.

multiplyAmount :: Quantity -> Amount -> Amount Source #

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

multiplyQuantities :: Quantity -> Quantity -> Quantity Source #

Multiply two quantities. Equivalent to Decimal's (*), but much faster in the usual case: that one multiplies via Rational, rounds to 255 decimal places and normalises via Rational again, costing kilobytes of allocation per multiplication. Here the mantissas are multiplied directly, and the result normalised the same way (to the minimal exponent), whenever the exponents' sum fits in a Decimal.

invertAmount :: Amount -> Amount Source #

Invert an amount (replace its quantity q with 1/q). The amount's transacted price, if any, is not changed. An amount with zero quantity is left unchanged.

styles

amountstyle :: AmountStyle Source #

Default amount style

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

Deprecated: please use styleAmounts instead

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

Deprecated: please use styleAmounts instead

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

Deprecated: please use styleAmounts instead

amountStyleSetRounding :: Rounding -> AmountStyle -> AmountStyle Source #

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

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

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

amountUnstyled :: Amount -> Amount Source #

Reset this amount's display style to the default.

commodityStylesFromAmounts :: [Amount] -> Either String (Map CommoditySymbol AmountStyle) Source #

Given a list of amounts, in parse order (roughly speaking; see journalStyleInfluencingAmounts), build a map from their commodity names to standard commodity display formats. Can return an error message eg if inconsistent number formats are found.

Though, these amounts may have come from multiple files, so we shouldn't assume they use consistent number formats. Currently we don't enforce that even within a single file, and this function never reports an error.

addAmountStyle :: Amount -> Map CommoditySymbol AmountStyle -> Map CommoditySymbol AmountStyle Source #

Add an amount's style to a map of commodity styles, merging it into its commodity's canonical style so far (see canonicalStyle). Amounts are added in reverse order of appearance, so that the first amount's general style wins. When the amount's style adds nothing new, which is the common case, the map is returned unchanged.

getAmounts :: Amount -> [Amount] Source #

Get an amount and its attached cost amount if any. Returns one or two amounts.

rendering

data AmountFormat Source #

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.

  • displayCostBasis :: Bool

    Whether to display Amounts' cost basis (Ledger-style lot syntax).

  • displayColour :: Bool

    Whether to ansi-colourise negative Amounts.

  • displayQuotes :: Bool

    Whether to enclose complex symbols in quotes (normally true)

  • displayLedgerLotSyntax :: Bool

    Whether to display cost basis using Ledger-style lot syntax ({COST} DATE) instead of hledger consolidated syntax.

Instances

Instances details
Default AmountFormat Source #

By default, display amounts using defaultFmt amount display options.

Instance details

Defined in Hledger.Data.Amount

Methods

def :: AmountFormat

Show AmountFormat Source # 
Instance details

Defined in Hledger.Data.Amount

Methods

showsPrec :: Int -> AmountFormat -> ShowS

show :: AmountFormat -> String

showList :: [AmountFormat] -> ShowS

defaultFmt :: AmountFormat Source #

Display amounts without colour, and with various other defaults.

fullZeroFmt :: AmountFormat Source #

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

noCostFmt :: AmountFormat Source #

Like defaultFmt but don't show costs or cost basis.

oneLineFmt :: AmountFormat Source #

Like defaultFmt but display all amounts on one line.

oneLineNoCostFmt :: AmountFormat Source #

Like noCostFmt but display all amounts on one line.

machineFmt :: AmountFormat Source #

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

showAmount :: Amount -> String Source #

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 Source #

Like showAmount but uses the given amount format.

showAmountsDistinctly :: AmountFormat -> Amount -> Amount -> (String, String) Source #

Render two similar amounts as strings using the given format, at enough decimal display precision that the two strings differ. First tries each at its own full (capped) precision; if the strings already differ, both are returned as-is (preserving any per-amount asymmetry). Otherwise both amounts' display precision is increased in lockstep until the strings are distinct, capped at the larger of the two amounts' internal precisions. If the amounts are equal at the Decimal level the loop terminates at the cap. Useful in error messages that compare two amounts which would otherwise round to identical-looking text.

showAmountB :: AmountFormat -> Amount -> WideBuilder Source #

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.

showAmountQuantity :: Bool -> Amount -> WideBuilder Source #

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. With a true first argument, if there are no decimal digits but there are digit group separators, it shows the amount with a trailing decimal mark to help disambiguate it for parsing.

showAmountCostBasis :: Amount -> String Source #

Show an amount's cost basis as consolidated lot syntax: {DATE, LABEL, COST}.

showAmountCostBasisLedger :: Amount -> String Source #

Show an amount's cost basis as Ledger-style lot syntax: {LOTCOST} LOTDATE. Kept for future --ledger-lot-syntax flag (step 3).

cshowAmount :: Amount -> String Source #

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 Source #

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

showAmountWithZeroCommodity = wbUnpack . showAmountB defaultFmt{displayZeryCommodity=True}

showAmountDebug :: Amount -> String Source #

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

showAmountWithoutCost :: Amount -> String Source #

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

showAmountWithoutCost = wbUnpack . showAmountB noCostFmt

amountSetPrecision :: AmountPrecision -> Amount -> Amount Source #

Set an amount's display precision.

amountSetPrecisionMin :: Word8 -> Amount -> Amount Source #

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

amountSetPrecisionMax :: Word8 -> Amount -> Amount Source #

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

withPrecision :: Amount -> AmountPrecision -> Amount Source #

Set an amount's display precision, flipped.

amountSetFullPrecision :: Amount -> Amount Source #

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 Source #

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 Source #

How many internal decimal digits are stored for this amount ?

amountDisplayPrecision :: Amount -> Word8 Source #

How many decimal digits will be displayed for this amount ?

defaultMaxDisplayPrecision :: Word8 Source #

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

setAmountInternalPrecision :: Word8 -> Amount -> Amount Source #

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 Source #

setAmountInternalPrecision with arguments flipped.

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

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

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

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

amountStripCost :: Amount -> Amount Source #

Strip all costs from an Amount

MixedAmount

nullmixedamt :: MixedAmount Source #

The empty mixed amount.

missingmixedamt :: MixedAmount Source #

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

isMissingMixedAmount :: MixedAmount -> Bool Source #

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 Source #

Convert amounts in various commodities into a mixed amount.

mixedAmount :: Amount -> MixedAmount Source #

Create a MixedAmount from a single Amount.

maAddAmount :: MixedAmount -> Amount -> MixedAmount Source #

Add an Amount to a MixedAmount, and then normalise that. (Any cost basis on the amounts will be lost.)

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

Add a collection of Amounts to a MixedAmount, and then normalise that. (Any cost basis on the amounts will be lost.)

amounts :: MixedAmount -> [Amount] Source #

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] Source #

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. sorted by commodity and transacted cost.

amountsPreservingZeros :: MixedAmount -> [Amount] Source #

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 Source #

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

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

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

filterMixedAmountByCommodity :: CommoditySymbol -> MixedAmount -> MixedAmount Source #

Return a MixedAmount containing just the amount of the requested commodity that was in the original mixed amount (or zero if there was none).

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

Apply a transform to a mixed amount's component Amounts.

unifyMixedAmount :: MixedAmount -> Maybe Amount Source #

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 Source #

Remove all transacted costs and cost bases from a MixedAmount.

arithmetic

mixedAmountCost :: MixedAmount -> MixedAmount Source #

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

mixedAmountCostBasis :: MixedAmount -> MixedAmount Source #

Convert all component amounts to cost basis (or else transacted cost) where possible (see amountCostBasis).

maNegate :: MixedAmount -> MixedAmount Source #

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

maPlus :: MixedAmount -> MixedAmount -> MixedAmount Source #

Sum two MixedAmounts. (Any cost basis on the amounts will be lost.)

maMinus :: MixedAmount -> MixedAmount -> MixedAmount Source #

Subtract a MixedAmount from another. (Any cost basis on the amounts will be lost.)

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

Sum a collection of MixedAmounts. (Any cost basis on the amounts will be lost.)

divideMixedAmount :: Quantity -> MixedAmount -> MixedAmount Source #

Divide a mixed amount's quantities (and total costs, if any) by a constant. Returns the mixed amount unchanged when the divisor is zero.

divideMixedAmountAndUpdatePrecision :: Quantity -> MixedAmount -> MixedAmount Source #

Like divideMixedAmount, but sets each component amount's display precision to exactly the number of significant decimal digits in the quotient (capped at defaultMaxDisplayPrecision), so the quotient's digits stay visible without adding trailing zeros. Use this when the quotient is intended for display in a journal entry; for aggregate report cells, prefer divideMixedAmount.

multiplyMixedAmount :: Quantity -> MixedAmount -> MixedAmount Source #

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

averageMixedAmounts :: Foldable f => f MixedAmount -> MixedAmount Source #

Calculate the average of some mixed amounts.

sumAndAverageMixedAmounts :: Foldable f => f MixedAmount -> (MixedAmount, MixedAmount) Source #

Calculate the sum and average of some mixed amounts.

isNegativeAmount :: Amount -> Bool Source #

Is this amount negative ? The cost is ignored.

isNegativeMixedAmount :: MixedAmount -> Maybe Bool Source #

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

amountRoundedQuantity :: Amount -> Quantity Source #

Round an Amount's Quantity (internally) to match its display precision. If that is unset or NaturalPrecision, this does nothing.

mixedAmountIsZero :: MixedAmount -> Bool Source #

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

maIsZero :: MixedAmount -> Bool Source #

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

A convenient alias for mixedAmountIsZero.

maIsNonZero :: MixedAmount -> Bool Source #

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

A convenient alias for not . mixedAmountIsZero.

mixedAmountLooksZero :: MixedAmount -> Bool Source #

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

styles

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

Deprecated: please use mixedAmountSetStyle False (or styleAmounts) instead

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

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 Source #

Deprecated: please use styleAmounts instead

mixedAmountUnstyled :: MixedAmount -> MixedAmount Source #

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

rendering

showMixedAmount :: MixedAmount -> String Source #

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 Source #

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

showMixedAmountsDistinctly :: AmountFormat -> MixedAmount -> MixedAmount -> (String, String) Source #

Like showAmountsDistinctly but for MixedAmount. First tries each at its own precision; if those strings already differ, they are returned as-is. Otherwise display precision is increased uniformly (across all commodity components) in lockstep until the rendered strings are distinct, capped at the larger of the two amounts' internal precisions.

showMixedAmountOneLine :: MixedAmount -> String Source #

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

showMixedAmountDebug :: MixedAmount -> String Source #

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

showMixedAmountWithoutCost :: Bool -> MixedAmount -> String Source #

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 Source #

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 Source #

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 Source #

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

showMixedAmountB :: AmountFormat -> MixedAmount -> WideBuilder Source #

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] Source #

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)] Source #

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

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

Like showMixedAmountOneLineB but returns the individual amounts as separate builders, along with their amounts, and without any padding or eliding (displayMinWidth and displayMaxWidth are ignored). Used eg for HTML output, where each amount gets its own styled element.

wbToText :: WideBuilder -> Text Source #

Convert a WideBuilder to a strict Text.

wbUnpack :: WideBuilder -> String Source #

Convert a WideBuilder to a String.

mixedAmountSetPrecision :: AmountPrecision -> MixedAmount -> MixedAmount Source #

Set the display precision in the amount's commodities.

mixedAmountSetFullPrecision :: MixedAmount -> MixedAmount Source #

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

mixedAmountSetFullPrecisionCapped :: MixedAmount -> MixedAmount Source #

Like mixedAmountSetFullPrecision, except that an amount with a repeating decimal (from division, rounded at the 255th decimal place) gets 8 decimal places, not 255.

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

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 Source #

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 Source #

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

misc.

showPriceDirective :: PriceDirective -> Text Source #

Render a price directive in journal format ("P DATE COMMODITY AMOUNT"). Always shows the to-currency, even on a zero quantity, so the directive round-trips back to the same conversion pair.

Orphan instances

Monoid MixedAmount Source # 
Instance details

Semigroup MixedAmount Source # 
Instance details

Methods

(<>) :: MixedAmount -> MixedAmount -> MixedAmount

sconcat :: NonEmpty MixedAmount -> MixedAmount

stimes :: Integral b => b -> MixedAmount -> MixedAmount

Num Amount Source # 
Instance details

Num MixedAmount Source # 
Instance details

HasAmounts Amount Source # 
Instance details

HasAmounts BalanceData Source # 
Instance details

HasAmounts MixedAmount Source # 
Instance details

HasAmounts a => HasAmounts (Account a) Source # 
Instance details

HasAmounts a => HasAmounts (PeriodData a) Source # 
Instance details