I think this was posted a while back (I remember there was a little contest to see who could write the best function

) but I've written it again with comments explaining each step. Sorry for using the same variable names over and over, that was probably confusing but it seemed more efficient to me for some reason

well it's sparing a tiny bit of memory I suppose!

function roundval(n#)
rem Store n as an integer, discarding the fraction.
n = n#
rem Adding n to itself reveals whether it should be rounded up or down:
rem Two halves make a whole, so fractions of at least 0.5 will be rounded up,
rem whereas two lesser fractions combined will fail to produce a whole number and therefore be rounded down.
inc n#,n#
rem This subtraction takes the integer value of n from the sum of 2n and discards the fraction by storing the
rem result in an integer variable. Now we see why the above addition was so important, because now all we
rem have left is an integer, so either n was rounded up or it's fraction wasn't large enough to do so.
n = n#-n
rem The function works for negative numbers too because we only ever talk in terms of n, so if n is negative, the addition and subtraction of n is also negative.
endfunction n

Everything worthwhile requires effort.