casting?

Monkey Forums/Monkey Programming/casting?

svero(Posted 2011) [#1]
So I ran into the following..

local t:Float
For Local i:=0 To 4
t = i/LOD
Next

t is supposed to be some value between 0->1 .. but its always zero
because i is an int.. the division gives me an int back and assigns zero to the t variable.

So.. I got around this by creating a temporary floating point i variable but I'm wondering if theres anything equivalent to a c++ cast in monkey? to deal with issues like these


slenkar(Posted 2011) [#2]
to cast just do this
 
local i:Float
local j:Int

i=9.5
j=Int(i)


its very easy :)


Warpy(Posted 2011) [#3]
svero - casting is done like so:
t = Float(i)/LOD


i is cast to a float, so the division then returns a float.


svero(Posted 2011) [#4]
Thanks.. I tried (Float)i but I guess you know the results :-)


Samah(Posted 2011) [#5]
You can cast either side, too.
t = i/Float(LOD)