Program round_function !------------------------------------------------------------------------------ !Program: Round Function !Author: Chris Harper !Date: 2/23/2008 !------------------------------------------------------------------------------ IMPLICIT NONE !declare function real :: round !test round function with a few values print *, "10.4567 rounded to 2 places is ", round(10.4567, 2) print *, "10.453 rounded to 2 places is ", round(10.453, 2) print *, "0.75 rounded to 0 places is ", round(0.75, 0) print *, "0.05 rounded to 1 places is ", round(0.05, 1) print *, "1.11111 rounded to 3 places is ", round(1.11111, 3) end real function Round(Amount, N) IMPLICIT NONE real , intent (IN) :: Amount integer , intent (IN) :: N real :: fPart integer :: power10, iPart power10 = 10 ** N iPart = aint(amount) fpart = (Amount - iPart) * power10 !shift the decimal point down to the precision we want Round = iPart + (real(nint(fpart)) / power10) !using nearest int on fparts rounds off the decimal end function