com.r3corda.core.contracts / Amount

# Amount

`data class Amount<T> : Comparable<Amount<T>>`

Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest amount used in whatever underlying thing the amount represents.

Amounts of different tokens do not mix and attempting to add or subtract two amounts of different currencies will throw IllegalArgumentException. Amounts may not be negative. Amounts are represented internally using a signed 64 bit value, therefore, the maximum expressable amount is 2^63 - 1 == Long.MAX_VALUE. Addition, subtraction and multiplication are overflow checked and will throw ArithmeticException if the operation would have caused integer overflow.

TODO: It may make sense to replace this with convenience extensions over the JSR 354 MonetaryAmount interface, in particular for use during calculations. This may also resolve... TODO: Think about how positive-only vs positive-or-negative amounts can be represented in the type system. TODO: Add either a scaling factor, or a variant for use in calculations.

### Parameters

`T` - the type of the token, for example Currency.

### Constructors

<init> | `Amount(amount: BigDecimal, currency: T)``Amount(quantity: Long, token: T)` Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. Note that quantity is not necessarily 1/100ths of a currency unit, but are the actual smallest amount used in whatever underlying thing the amount represents.

### Properties

quantity | `val quantity: Long`
token | `val token: T`

### Functions

compareTo | `fun compareTo(other: Amount<T>): Int`
div | `operator fun div(other: Long): Amount<T>` `operator fun div(other: Int): Amount<T>`
minus | `operator fun minus(other: Amount<T>): Amount<T>`
plus | `operator fun plus(other: Amount<T>): Amount<T>`
times | `operator fun times(other: Long): Amount<T>` `operator fun times(other: Int): Amount<T>`
toString | `fun toString(): String`

### Extension Properties

CASH | `val Amount<Currency>.CASH: State` An extension property that lets you write 100.DOLLARS.CASH
OBLIGATION | `val Amount<Issued<Currency>>.OBLIGATION: State<Currency>`
STATE | `val Amount<Issued<Currency>>.STATE: State` An extension property that lets you get a cash state from an issued token, under the NullPublicKey

### Extension Functions

issued by | `infix fun Amount<Currency>.issued by(deposit: PartyAndReference): Amount<Issued<Currency>>`
issuedBy | `infix fun Amount<Currency>.issuedBy(deposit: PartyAndReference): Amount<Issued<Currency>>`
withoutIssuer | `fun <T> Amount<Issued<T>>.withoutIssuer(): Amount<T>` Strips the issuer and returns an Amount of the raw token directly. This is useful when you are mixing code that cares about specific issuers with code that will accept any, or which is imposing issuer constraints via some other mechanism and the additional type safety is not wanted.