hledger-lib-0.13: Core types and utilities for working with hledger (or c++ ledger) data.

Hledger.Data.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
90 apples
0
```

An amount may also have a per-unit price, or conversion rate, in terms of some other commodity. If present, this is displayed after @:

```  EUR 3 @ \$1.35
```

A `MixedAmount` is zero or more simple amounts. Mixed amounts are usually normalised so that there is no more than one amount in each commodity, and no zero amounts (or, there is just a single zero amount and no others.):

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

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

# Documentation

amountop :: (Double -> Double -> Double) -> Amount -> Amount -> AmountSource

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.)

Convert an amount to the specified commodity using the appropriate exchange rate (which is currently always 1).

Convert mixed amount to the specified commodity

Convert an amount to the commodity of its saved price, if any.

Get the string representation of an amount, based on its commodity's display settings.

Get the string representation of an amount, based on its commodity's display settings except using the specified precision.

Get the unambiguous string representation of an amount, for debugging.

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

Get the string representation of an amount, without any price or commodity symbol.

Get the string representation of the number part of of an amount, using the display precision from its commodity.

Add thousands-separating commas to a decimal number string

Does this amount appear to be zero when displayed with its given precision ?

Is this amount really zero, regardless of the display precision ? Since we are using floating point, for now just test to some high precision.

Is this amount negative ? The price is ignored.

Access a mixed amount's components.

Does this mixed amount appear to be zero - empty, or containing only simple amounts which appear to be zero ?

Is this mixed amount really zero ? See isReallyZeroAmount.

Is this mixed amount negative, if it can be normalised to a single commodity ?

Is this mixed amount really zero, after converting to cost commodities where possible ?

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.

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 "".

Get the string representation of a mixed amount, showing each of its component amounts with the specified precision, ignoring their commoditys' display precision settings. NB a mixed amount can have an empty amounts list in which case it shows as "".

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

Get the string representation of a mixed amount, but without any @ prices.

Get the string representation of a mixed amount, and if it appears to be all zero just show a bare 0, ledger-style.

Get the string representation of a mixed amount, or a bare 0, without any @ prices.

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.

Set a mixed amount's commodity to the canonicalised commodity from the provided commodity map.

Set an amount's commodity to the canonicalised commodity from the provided commodity map.

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.

Convert a mixed amount's component amounts to the commodity of their saved price, if any.

The empty simple amount.

The empty mixed amount.

A temporary value for parsed transactions which had no amount specified.