tez
LIGO offers some Tezos-specific data types. Here we list some of them. Others have their own dedicated section.
The token unit on Tezos is called tez
in LIGO. There are several
ways to write literal values of type tez
:
- units of millionth 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
.
The type is
tez
, notmutez
--- which is a suffix to write literals.
Note that large amounts, like with numerical values of type int
and
nat
, can be expressed using underscores to separate groups of
digits, like 1_000mutez
(one thousand mutez) or 0.000_004tez
.
Adding
Addition in LIGO is accomplished by means of the +
infix
operator. Some type constraints apply, for example you cannot add a
value of type tez
to a value of type nat
.
In the following example you can find a series of arithmetic
operations, including various numerical types. However, some bits
remain in comments as they would otherwise not compile, for example,
adding a value of type int
to a value of type tez
is invalid. Note
that adding an integer to a natural number produces an integer.
Subtracting
Since subtracting two amounts could result in a negative amount,
subtraction of two tez
amounts result in an
optional amount, like so:
Multiplying
You can multiply nat
and tez
values:
Dividing
The division of two tez
values results into 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: