Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Integer variables

Status
Not open for further replies.

keikosaito

Technical User
Oct 13, 2012
4
PE

Hello again :)

I was doing some really basic programs for meteorological variables and things related, but I noticed that when I write implicit none and then define my variable that must be integer the value is wrong, because it is rounded down, not rounded to the closest integer value, so when relative humidity must be 80 (real value: 79.999990) it is 79, is there a way to fix it? Thanks in anticipation :)
 
Numbers in Fortran truncate towards zero. Try calling NINT on the value.
Code:
x = 1.7
y = 2.4
nx = nint(x)
ny = nint(y)
print *, nx, ny
You should get 2 in both cases. There is also AINT, CEILING and FLOOR for rounding in specific directions. Just depends on what your truncation rules are.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top