Convert to integer type
FORTRAN 77 and later
result = int(a [, kind))
a
- Shall be of type integer
, real
, or complex
.kind
- (Optional) An integer
initialization expression indicating the kind parameter of the result.These functions return a integer
variable or array under the following rules:
If a
is of type integer
, int(a) = a
If a
is of type real
and |a| \\lt 1
, int(a)
equals 0
. If |a| \\geq 1
, then int(a)
equals the largest integer that does not exceed the range of a
and whose sign is the same as the sign of a
.
If a
is of type complex
, rule 2 is applied to the real part of a
.
program test_int
integer :: i = 42
complex :: z = (-3.7, 1.0)
print *, int(i)
print *, int(z), int(z,8)
end program