Ledger.Amount
Description

An Amount is some quantity of money, shares, or anything else.

A simple amount is a Commodity, quantity pair:

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

A MixedAmount is zero or more simple amounts:

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

Amounts often have a price per unit, or conversion rate, in terms of another commodity. If present, this is displayed after @:

EUR 3 @ \$1.35

A normalised mixed amount has at most one amount in each commodity-price, and no zero amounts (or it has just a single zero amount and no others.)

In principle we can convert an amount to any other commodity to which we have a known sequence of conversion rates; in practice we only do one conversion step (eg to show cost basis with -B).

We can do limited arithmetic with simple or mixed amounts: either price-preserving arithmetic with similarly-priced amounts, or price-discarding arithmetic which ignores and discards prices.

Synopsis
 amountop :: (Double -> Double -> Double) -> Amount -> Amount -> Amount convertAmountTo :: Commodity -> Amount -> Amount costOfAmount :: Amount -> Amount showAmount :: Amount -> String showAmountWithoutPrice :: Amount -> String showAmount' :: Amount -> String punctuatethousands :: String -> String isZeroAmount :: Amount -> Bool isReallyZeroAmount :: Amount -> Bool amounts :: MixedAmount -> [Amount] isZeroMixedAmount :: MixedAmount -> Bool isReallyZeroMixedAmount :: MixedAmount -> Bool mixedAmountEquals :: MixedAmount -> MixedAmount -> Bool showMixedAmount :: MixedAmount -> String showMixedAmountWithoutPrice :: MixedAmount -> String showMixedAmountOrZero :: MixedAmount -> String showMixedAmountOrZeroWithoutPrice :: MixedAmount -> String normaliseMixedAmount :: MixedAmount -> MixedAmount normaliseMixedAmountIgnoringPrice :: MixedAmount -> MixedAmount costOfMixedAmount :: MixedAmount -> MixedAmount nullamt :: Amount nullmixedamt :: MixedAmount missingamt :: MixedAmount
Documentation
 amountop :: (Double -> Double -> Double) -> Amount -> Amount -> Amount Source
Apply a binary arithmetic operator to two amounts, converting to the second one's commodity (and display precision), discarding any price information. (Using the second commodity is best since sum and other folds start with a no-commodity amount.)
 convertAmountTo :: Commodity -> Amount -> Amount Source
Convert an amount to the specified commodity using the appropriate exchange rate (which is currently always 1).
 costOfAmount :: Amount -> Amount Source
Convert an amount to the commodity of its saved price, if any.
 showAmount :: Amount -> String Source
Get the string representation of an amount, based on its commodity's display settings.
 showAmountWithoutPrice :: Amount -> String Source
Get the string representation of an amount, without any @ price.
 showAmount' :: Amount -> String Source
Get the string representation (of the number part of) of an amount
 punctuatethousands :: String -> String Source
Add thousands-separating commas to a decimal number string
 isZeroAmount :: Amount -> Bool Source
Does this amount appear to be zero when displayed with its given precision ?
 isReallyZeroAmount :: Amount -> Bool Source
Is this amount really zero, regardless of the display precision ? Since we are using floating point, for now just test to some high precision.
 amounts :: MixedAmount -> [Amount] Source
Access a mixed amount's components.
 isZeroMixedAmount :: MixedAmount -> Bool Source
Does this mixed amount appear to be zero - empty, or containing only simple amounts which appear to be zero ?
 isReallyZeroMixedAmount :: MixedAmount -> Bool Source
Is this mixed amount really zero ? See isReallyZeroAmount.
 mixedAmountEquals :: MixedAmount -> MixedAmount -> Bool Source
MixedAmount derives Eq in Types.hs, but that doesn't know that we want \$0 = EUR0 = 0. Yet we don't want to drag all this code in there. When zero equality is important, use this, for now; should be used everywhere.
 showMixedAmount :: MixedAmount -> String Source
Get the string representation of a mixed amount, showing each of its component amounts. NB a mixed amount can have an empty amounts list in which case it shows as "".
 showMixedAmountWithoutPrice :: MixedAmount -> String Source
Get the string representation of a mixed amount, but without any @ prices.
 showMixedAmountOrZero :: MixedAmount -> String Source
Get the string representation of a mixed amount, and if it appears to be all zero just show a bare 0, ledger-style.
 showMixedAmountOrZeroWithoutPrice :: MixedAmount -> String Source
Get the string representation of a mixed amount, or a bare 0, without any @ prices.
 normaliseMixedAmount :: MixedAmount -> MixedAmount Source
Simplify a mixed amount by combining any component amounts which have the same commodity and the same price. Also removes zero amounts, or adds a single zero amount if there are no amounts at all.
 normaliseMixedAmountIgnoringPrice :: MixedAmount -> MixedAmount Source
Simplify a mixed amount by combining any component amounts which have the same commodity, ignoring and discarding their unit prices if any. Also removes zero amounts, or adds a single zero amount if there are no amounts at all.
 costOfMixedAmount :: MixedAmount -> MixedAmount Source
Convert a mixed amount's component amounts to the commodity of their saved price, if any.
 nullamt :: Amount Source
The empty simple amount.
 nullmixedamt :: MixedAmount Source
The empty mixed amount.
 missingamt :: MixedAmount Source
A temporary value for parsed transactions which had no amount specified.