Rounding up a variable

Anything that doesn't fit elsewhere.
Post Reply
auatai
Posts: 29
Joined: Mon Sep 14, 2009 6:33 am

Rounding up a variable

Post by auatai »

Hi,
Is there any function to round up a floating point variable within the hoc code?

thanks and regards
ted
Site Admin
Posts: 6303
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Rounding up a variable

Post 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)
  }
}
Post Reply