Page 1 of 1

Rounding up a variable

Posted: Tue Jun 29, 2010 12:29 am
by auatai
Hi,
Is there any function to round up a floating point variable within the hoc code?

thanks and regards

Re: Rounding up a variable

Posted: Tue Jun 29, 2010 2:16 pm
by ted
int truncates toward 0, returning the integer portion of its argument. So roll your own:

Code: Select all

func round() {
  if ($1>0) {
    return int($1+0.5)
  } else {
    return int($1-0.5)
  }
}