Lahey/Fujitsu Fortran

NINT Function


The NINT function returns the nearest INTEGER to a REAL argument.


NINT (a [, kind])

Required Arguments

a is an INTENT(IN) scalar or array of type REAL.

Optional Arguments

kind is INTENT(IN) and determines the kind of the result. It must be a scalar INTEGER expression that can be evaluated at compile time. To maintain portability, this argument should be the result of a KIND Function or SELECTED_INT_KIND Function.


The result is of type INTEGER. If kind is present the result is that kind; otherwise it is a default INTEGER.

If a > 0, the result has the value INT(a+0.5);

If a ≤ 0, the result has the value INT(a-0.5)


real :: a=1.5,aa(3)=(/-.5,0.,.5/) write(*,*) nint(a) ! writes 2 write(*,*) nint(-a) ! writes -2 write(*,*) nint(aa) ! writes -1 0 1 write(*,*) nint(-aa) ! writes 1 0 -1

See Also

KIND Function