Forums > MaxMSP

Rounding Numbers in Max

April 17, 2010 | 3:27 pm

Hi there, is it possible to round a decimal number to the nearest whole number.

So if i inputted 60.9 and 70.2, it would always output 70.

Thanks.



kjg
April 17, 2010 | 3:37 pm

[+ 0.5] >> [int]


April 17, 2010 | 3:40 pm

Sure – slap an integer number box on the float output, which truncates. If that doesn’t float your boat and you want to round "like humans do," then add. .5 and then slap an integer number box on the float output.



Ch
April 17, 2010 | 3:42 pm

or just use [round]


April 17, 2010 | 3:43 pm

The [round ] object is more convenient.


April 17, 2010 | 4:09 pm

Thanks everyone, feel a bit silly now :P


April 18, 2010 | 12:14 pm

[expr (int($f1-0.5))*($f1<0) + (int($f1+0.5))*($f1>=0)]


April 23, 2010 | 10:25 pm

a more concise one int($f1 + ($f1 > 0) - 0.5).


April 28, 2010 | 5:20 pm

nice one, danke ej


Viewing 9 posts - 1 through 9 (of 9 total)