Convert whole-number float to int


    Mar 12 2007 | 5:25 pm
    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

    • Mar 12 2007 | 5:38 pm
      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 >
    • Mar 12 2007 | 5:39 pm
      I should clarify that I want to keep the non-whole-number floats as floats and only convert the whole-number ones.
      -Brian
    • Mar 12 2007 | 5:42 pm
    • Mar 12 2007 | 5:52 pm
      Julien,
      That works fabulously, thank you!
    • Mar 12 2007 | 6:26 pm
    • Jul 21 2012 | 10:53 am
      I would really like to see what was once written in these blank posts...
    • Jul 21 2012 | 2:56 pm
      i can only guess.
      [if int($f1)==$f1 then $f1 else out2 $f1]
      then do the type conversion for the whole numbers.
      -110
    • Jul 21 2012 | 6:06 pm
      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.
    • Jul 21 2012 | 10:03 pm
      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. ;)
    • Jul 23 2012 | 10:48 am
      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).