- Home /
Question by
ic3t3a2000 · Aug 13, 2013 at 05:18 AM ·
javascriptfloatc# to javascriptc
variable from int to float in javascript for loop
I have a for loop that is in c and I am trying to convert it to javascript. On the last line of the below code the x and z variables in the loop are changed from int to float using a (float) statement. What is the javascript equivalent to (float)?
int x, z;
for(z=0; z < vsize_z; z++)
{
for(x=0; x < vsize_x; x++)
{
vertices[ z * vsize_x + x ] = new Vector3( x*tileSize, 0, z*tileSize );
normals[ z * vsize_x + x ] = Vector3.up;
uv[ z * vsize_x + x ] = new Vector2( (float)x / vsize_x, (float)z / vsize_z );
Comment
just try a simple search.. first two results for me were http://stackoverflow.com/questions/4057489/javascript-convert-int-to-float and http://stackoverflow.com/questions/4293230/how-do-i-convert-an-integer-to-a-float-in-javascript
Answer by IgorAherne · Aug 13, 2013 at 07:59 AM
UnityScript allows to cast without any typecasting like
var aFloat:float; var aInt:int;
aInt= aFloat; will work and the conversion will simply truncate the result, not round so 1.9 becomes 1.
Vise versa for you