tez
The token unit on Tezos is called tez in LIGO. There are several
ways to write literal values of type tez:
- Units of millionths of
tez, using the suffixmutezafter a natural number, like10000mutezor0mutez - Units of
tez, using the suffixtzortez, like3tzor3tez - Decimal amounts of
tzortez, like12.3tzor12.4tez
LIGO uses the type
tez, notmutez. The suffixmutezis only for writing literal amounts of millionths of tez.
Like integers and nats, you can express large amounts of tez with underscores to separate groups of
digits, like 1_000mutez (one thousand mutez) or 0.000_004tez.
Adding
You can add amounts of tez with the + operator, as in the following example.
You cannot add amounts of tez to integers or nats.
Subtracting
Because subtracting two amounts could result in a negative amount,
subtracting two tez amounts results in an
optional amount, as in these examples:
Multiplying
You can multiply nat and tez values:
Dividing
Because LIGO features neither floating-point nor fixed-point
arithmetic, division in LIGO is Euclidean.
Dividing two tez values returns the quotient of the operation as a nat.
Euclidean Division
For cases when you need both the quotient and the remainder, LIGO
provides the ediv operation. ediv(x,y) returns Some (quotient,
remainder), unless y is zero, in which case it returns None. The
function ediv is overloaded to accept tez, beyond all the
combinations of natural and integer numbers: