how do you convert an int to a float in HScript

   8842   4   3
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
This is a bit of an embarrasing question, but is there a way to do that that does not involve me using the floor(someInt) function? I know there is an int() a atof, a ftoa, hell there is even a hex(), but no float()?

if not, RFEEEEE!
-G
User Avatar
Staff
2540 posts
Joined: July 2005
Offline
I believe hscript itself has no idea of what is an int. I think everything is float.

Some functions work with integers and will round automatically if you feed in a float).

The functions you listed will strip off remainder leaving whole numbers but they still are floats.
There's at least one school like the old school!
User Avatar
Member
1799 posts
Joined: Oct. 2010
Offline
In my case, I brought an int attr via a prim expression then dividing it by a float. This resulted on an integer result, which was bad. In ex and python, I would do the float conversion, but in expression, I got stuck ): floor forces the result to float which did the trick , but it seems strange not to have a float () function
-G
User Avatar
Member
17 posts
Joined: Nov. 2017
Offline
Years later, I was wondering the same and found this post.
My solution, multiplying your value by a float. so for example:
ch("../intValue")
is an int
ch("../intValue")*1.0
is a float
User Avatar
Member
7802 posts
Joined: Sept. 2011
Offline
Channel referencing an int returns a float; no need for conversion before division.
  • Quick Links