Forums > MaxMSP

Rounding Numbers in Max


Apr 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
Apr 17 2010 | 3:37 pm

[+ 0.5] >> [int]

Apr 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
Apr 17 2010 | 3:42 pm

or just use [round]

Apr 17 2010 | 3:43 pm

The [round ] object is more convenient.

Apr 17 2010 | 4:09 pm

Thanks everyone, feel a bit silly now :P

Apr 18 2010 | 12:14 pm

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

Apr 23 2010 | 10:25 pm

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

Apr 28 2010 | 5:20 pm

nice one, danke ej

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

Forums > MaxMSP