ANINT

Elemental Intrinsic Function (Generic): Calculates the nearest whole number.

Syntax

result = ANINT (a [, kind] )

a
(Input) Must be of type real.

kind
(Optional; input) Must be a scalar integer initialization expression.

Results:

The result is of type real. If kind is present, the kind parameter is that specified by kind; otherwise, the kind parameter is that of a. If a is greater than zero, ANINT (a) has the value AINT (a + 0.5); if a is less than or equal to zero, ANINT (a) has the value AINT (a - 0.5).

Specific Name Argument Type Result Type
ANINTREAL(4) REAL(4)
DNINT REAL(8) REAL(8)
QNINT 1 REAL(16) REAL(16)
1 VMS and U*X

To truncate rather than round, use AINT.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: NINT

Examples

       REAL r1, r2
       r1 = ANINT(2.6)     ! returns the value 3.0
       r2 = ANINT(-2.6)    ! returns the value -3.0

! ANINT.F90 Calculates and adds tax to a purchase amount.
       REAL amount, taxrate, tax, total
       taxrate = 0.081
       amount = 12.99
       tax = ANINT (amount * taxrate * 100.0) / 100.0
       total = amount + tax
       WRITE (*, 100) amount, tax, total
  100  FORMAT ( 1X, 'AMOUNT', F7.2 /
      + 1X, 'TAX ', F7.2 /
      + 1X, 'TOTAL ', F7.2)
       END

ANINT (3.456) has the value 3.0.

ANINT (-2.798) has the value -3.0.