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 suffixmutez
after a natural number, like10000mutez
or0mutez
- Units of
tez
, using the suffixtz
ortez
, like3tz
or3tez
- Decimal amounts of
tz
ortez
, like12.3tz
or12.4tez
LIGO uses the type
tez
, notmutez
. The suffixmutez
is 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: