<div dir="ltr">I would suggest that you call Math.round() before casting, as to prevent undesirable effects: notice that in the example sent by ermina, 4.8 rounds down to 4 when cast to int, which could cause miscalculations <b>depending on your use case</b>.<div>The previous example would look something like this if we used Math.round():</div><div><br></div><div><font face="monospace">Math.round(pctPosInit) $ int =&gt; int pctPosInitInt;</font></div><div><font face="monospace">pctPosInitInt/100*myBuf.samples() =&gt; myBuf.pos;</font></div><div><br></div><div>Best regards!</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jan 21, 2020 at 12:49 PM ermina &lt;<a href="mailto:ermina@studioplume.com">ermina@studioplume.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
to convert a float to an int,<br>
you need to explicitly cast the value with<br>
4.8 $ int =&gt; int foo;  // foo == 4<br>
(as written here: <a href="https://chuck.cs.princeton.edu/doc/language/oper.html" rel="noreferrer" target="_blank">https://chuck.cs.princeton.edu/doc/language/oper.html</a>)<br>
<br>
So you would do something like<br>
pctPosInit $ int =&gt; int pctPosInitInt<br>
pctPosInitInt/100*myBuf.samples() =&gt; myBuf.pos;<br>
<br>
. e<br>
On 01/21/2020 02:08 PM, Mícheál Ó Catháin wrote:<br>
&gt; Hi<br>
&gt; What is the best way to convert a float to int in the following please?<br>
&gt; <br>
&gt; //I want to set myBuf.pos to a percentage of myBuf.samples()...<br>
&gt; //Start playing at say 40% through the total number of samples.<br>
&gt; <br>
&gt; 40.0 =&gt; float pctPosInit;<br>
&gt; pctPosInit/100*myBuf.samples() =&gt; myBuf.pos;<br>
&gt; <br>
&gt; <br>
&gt; This throws the error argument types don&#39;t match.<br>
&gt; I&#39;m not seeing how to convert the float to an int here.<br>
&gt; Thanks for your help!<br>
&gt; <br>
&gt; Micheal<br>
&gt; <br>
&gt; <br>
&gt; _______________________________________________<br>
&gt; chuck-users mailing list<br>
&gt; <a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
&gt; <a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
&gt; <br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" rel="noreferrer" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><span style="color:rgb(136,136,136)">Jean Menezes da Rocha</span><br></div></div></div></div>