How do you cast an int to a float?

I have tried absolutely everything and cannot seem to cast an integer to a float.

The closest I got is

if (test := float[float_val]) {}

Which displays the extremely odd error

Dynamic cast to `float` takes an float as its parameter, instead got int(3509)

Anybody have any ideas?

2 Likes

There is not a direct way to cast an int to a float. My current solution is this, a bit cheesy, but works:
var myFloatVar:float = 1.0 * myIntVar

4 Likes

Wow yea that’s a bit cheesy alright, bit of a shame. Thank you very much!

you can always use something like float fUrIntConvertedToFloat = static_cast(UrIntVariable);
Otherwise just pass the static_cast(UrIntVariable)

Hope this solved your little issue! :> Have fun!

This is Verse forum not C++

3 Likes

That’s very helpful cheers mate.

you re right I’m sorry mate!
thanks for that :>