I’ve searched through google (maybe I didn’t look hard enough) but I could not find how to turn Math.sqrt into an int.
I want to use Math.sqrt for a for loop and I guess I need it as an int but I can’t seem to figure out how to cast the result to an int. So how do I do it?
I tried something similar to Java:
(int) Math.sqrt(num);
But it didn’t work.
Thanks in advance 🙂
Use
Math.round,Math.ceil, orMath.floordepending on your specific rounding needs.‘For rounding numbers to integers one of Math.round, Math.ceil and Math.floor are preferable, and for a desired result that can be expressed as a 32 bit signed integer the bitwise operation described below might also suit.’
–http://www.jibbering.com/faq/faq_notes/type_convert.html#tcNumber