Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!bu.edu!buphy!merritt From: merritt@buphy.BU.EDU (Sean Merritt) Newsgroups: comp.lang.fortran Subject: Re: rounding a real to a whole number Message-ID: <67611@bu.edu.bu.edu> Date: 1 Nov 90 20:12:17 GMT References: Sender: news@bu.edu.bu.edu Organization: Physics Department, Boston University Lines: 39 In article u714092@eagle.larc.nasa.gov (prichard devon ) writes: > >what I want to do is to have a subroutine which, given a range of real >numbers, for example -123.445 -> 1033.02 , and choose whole numbers >outside that range. obviously the first application is axis values for >x-y plots. optionally, picking a 10-multiple of whole numbers ought to >be included; for -1.45567 -> 3.34112 , it should return -1.4 and 3.4 ... ^^^^^^^ -1.5 >Fortran intrinsics. I just can't get it to work correctly with truncations. > >anyone done this sort of thing listening out there? > >-- > |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| > | Devon Prichard making the world safe for helicopters ... | > | u714092@eagle.larc.nasa.gov, prichard@ias.larc.nasa.gov | > |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| This is how I've always done it: A = number to be rounded B = number of decimal places rounded to C = rounded number Simply include this line in a subroutine or function : C = INT(A*10**B+0.5)/10**B -sjm _________________________________________________________________________ Sean J. Merritt | Dept. of Physics,Boston University| SURSUM CORDA ! e-mail to:merritt@buphy.bu.edu |