hledger-lib-0.14: Reusable types and utilities for the hledger accounting tool and financial apps in general.

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.

# Documentation

Access a mixed amount's components.

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

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

Convert a mixed amount to the specified commodity, assuming an exchange rate of 1.

Convert an amount to the commodity of its saved price, if any. Notes: - price amounts must be MixedAmounts with exactly one component Amount (or there will be a runtime error) - price amounts should be positive, though this is not currently enforced

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

Divide an amount's quantity by some constant.

Divide a mixed amount's quantities by some constant.

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 ?

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

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

Simplify a mixed amount by removing redundancy in its component amounts, as follows: 1. sum amounts which have the same commodity (ignoring their price) 2. remove zero amounts 3. if there are no amounts at all, add a single zero amount

The empty simple amount.

The empty mixed amount.

Add thousands-separating commas to a decimal number string

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

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 an unambiguous string representation of a mixed amount for debugging.

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.

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

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