How To convert integer number to float number on max msp
![](https://secure.gravatar.com/avatar/6d2db068f84db158f06c7bba046d7c5c.jpg?s=120&d=mm&r=g)
HI, Every one Would you give me solution for my problem about converting integer number to float number. this is sample my script ,this work on mini audicle but still error on chuck objek on max msp. Thanks alot for your help ///////////////////////////////////////////// while (true) { Std.rand2(24 , 35) => int asoy; // integer number to be converted asoy $ float => float asik; //convert int to float ( asik => m.floatout// send data information to outlet chuck object on max msp 0.7::second => now; count + 2.0 => count; } ///////////////////////////////////////////////
![](https://secure.gravatar.com/avatar/fa5a8de5c6e6c5838fc8106b390c7a6d.jpg?s=120&d=mm&r=g)
Hey Tony!
Would you give me solution for my problem about converting integer number to float number.
I can try, but I don't have Max.
asoy $ float => float asik; //convert int to float (
That part looks fine to me.
asik => m.floatout// send data information to outlet chuck object on max msp
Shouldn't this be like; asik => m.floatout; // send data information to outlet chuck object on max msp Notice the added ";" If you don't need those variables elsewhere you may also be able to save some memory and will certainly save some code by simply doing; Std.rand2(24, 35) $ float => m.floatout; Assuming m.floatout() only takes a float as a argument the cast should actually be implicit and you will likely get away with this; Std.rand2(24, 35) => m.floatout; //being lazy is nice. Hope that helps, Kas.
![](https://secure.gravatar.com/avatar/6d2db068f84db158f06c7bba046d7c5c.jpg?s=120&d=mm&r=g)
Hey Kassen. Thanks a lot for your information. I have simple solution for that just add float number 0.0 to variable int number. Std.rand2( 0, 22 ) => int nilai=> shake.which; 0.0+nilai=>float hasil;// convert int variable nilai to float hasil => m.floatout
![](https://secure.gravatar.com/avatar/fa5a8de5c6e6c5838fc8106b390c7a6d.jpg?s=120&d=mm&r=g)
Hey Tony, I have simple solution for that just add float number 0.0 to variable int
number.
That will also work, as will multiplying by 1.0. I do feel that casting makes the intention more clear, which should improve code readability, but that might be a matter of taste and style. BTW, I feel that something called "floatout()" can be assumed to take a float and that as casting from int to float -where needed- is automatic in ChucK you should not need to do any of this here. If that doesn't work (again I don't have Max) then I'd call that a minor bug or at least a inconsistency. If I were you I'd look into whether you really need to do any of this and if so report it to chuck~'s maintainer as a suggestion. Yours, Kas.
participants (2)
-
Kassen
-
Tony Maryana