Convert whole-number float to int

bkshepard's icon

Hi folks,

I'm a long-time Max/MSP user, but first-time poster to the forum. I've always been able to find my answers by just searching the manuals or here, until now.

I am looking for a way to separate whole-number floats (ex. 2.0, 5.0, 12.0, etc.) from non-whole-number floats (1.3, 2.33333, 6.25, etc.) so that I can convert the whole-number floats to ints. Any ideas or suggestions will be greatly appreciated. Thanks.

-Brian

Alberto's icon

Can you use the modulo operator (%) to test for floats without
fractional amounts by dividing them by their integer portion and testing
for > 0?

On 3/12/07 1:25 PM, Brian Shepard wrote:
> Hi folks,
>
> I'm a long-time Max/MSP user, but first-time poster to the forum. I've always been able to find my answers by just searching the manuals or here, until now.
>
> I am looking for a way to separate whole-number floats (ex. 2.0, 5.0, 12.0, etc.) from non-whole-number floats (1.3, 2.33333, 6.25, etc.) so that I can convert the whole-number floats to ints. Any ideas or suggestions will be greatly appreciated. Thanks.
>
> -Brian
>

bkshepard's icon

I should clarify that I want to keep the non-whole-number floats as floats and only convert the whole-number ones.

-Brian

Owen Green's icon
bkshepard's icon

Julien,

That works fabulously, thank you!

bkshepard's icon
discopatrick's icon

I would really like to see what was once written in these blank posts...

Roman Thilenius's icon

i can only guess.

[if int($f1)==$f1 then $f1 else out2 $f1]

then do the type conversion for the whole numbers.

-110

discopatrick's icon

Ah ha... I didn't yet know that there were functions that could be used in 'if' and '(v)expr' statements. Perfect. Been looking for this for a while.

Roman Thilenius's icon

on the input side of IF everything from expr should work.

p.s. oh and right, comparison operators are not mentioned in the expr helpfile. ;)

Peter Castine's icon

Except "expr uses a C-like language" and comparison operators are, well, *operators* in C-derived languages.

+
-
/
*
%
==
!=
><
>=

&&
||
!
&
|
^<<
>>
~

sizeof(), address, and assignment operators aren't relevant in the context of [expr] or [if], so not included in the list. It occurs to me that the ternary operator ?: could be useful inside expr, but it's not supported (try it).