Convert whole-number float to int

Mar 12, 2007 at 5:25pm

Convert whole-number float to int

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

#30765
Mar 12, 2007 at 5:38pm

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
>

#98940
Mar 12, 2007 at 5:39pm

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

-Brian

#98941
Mar 12, 2007 at 5:42pm

#98942
Mar 12, 2007 at 5:52pm

Julien,

That works fabulously, thank you!

#98943
Mar 12, 2007 at 6:24pm

#98944
Mar 12, 2007 at 6:26pm

#98945
Mar 12, 2007 at 9:31pm

#98946
Jul 21, 2012 at 10:53am

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

#98947
Jul 21, 2012 at 2:56pm

i can only guess.

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

then do the type conversion for the whole numbers.

-110

#98948
Jul 21, 2012 at 6:06pm

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.

#98949
Jul 21, 2012 at 10:03pm

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. ;)

#98950
Jul 23, 2012 at 10:48am

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).

#98951

You must be logged in to reply to this topic.