Amount
Amount represents a positive quantity of some token (currency, asset, etc.), measured in quantity of the smallest representable units. The nominal quantity represented by each individual token is equal to the displayTokenSize. The scale property of the displayTokenSize should correctly reflect the displayed decimal places and is used when rounding conversions from indicative/displayed amounts in BigDecimal to Amount occur via the Amount.fromDecimal method.
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.
Parameters
the type of the token, for example Currency. T should implement TokenizableAssetInfo if automatic conversion to/from a display format is required.
Constructors
Properties
An extension property that lets you write 100.DOLLARS.CASH
the nominal display unit size of a single token, potentially with trailing decimal display places if the scale parameter is non-zero.
An extension property that lets you get a cash state from an issued token, under the NULL_PARTY
Functions
This method provides a token conserving divide mechanism.
The multiplication operator is supported to allow easy calculation for multiples of a primitive Amount. Note this is not a conserving operation, so it may not always be correct modelling of proper token behaviour. N.B. Division is not supported as fractional tokens are not representable by an Amount.
Convert a currency Amount to a decimal representation. For example, with an amount with a quantity of "1234" GBP, returns "12.34". The precise representation is controlled by the display token size ( from getDisplayTokenSize), which determines the size of a single token and controls the trailing decimal places via its scale property. Note that currencies such as the Bahraini Dinar use 3 decimal places, and it must not be presumed that this converts amounts to 2 decimal places.
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.