[Closed] units.formatValue as float != units.formatValue ?
Hey I’m trying to get units.formatValue from a string into a useful float
Ex:
x = sphere ()
-- returns : $Sphere:Sphere001 @ [0.000000,0.000000,0.000000]
xrad = x.radius
-- returns : 25.0
y = units.formatValue xrad
-- returns : "0.6349999958m"
g = y as float
-- returns : 1142.99
-- desired : 0.6349999958
Actually I figured out a way, while typing it. I went ahead and tried this instead which works as desired, with a very likely issue.
Edit :
x = sphere ()
-- returns : $Sphere:Sphere001 @ [0.000000,0.000000,0.000000]
xrad = x.radius
-- returns : 25.0
y = units.formatValue xrad
-- returns : "0.6349999958m"
z = filterString y "m"
-- returns : #("0.6349999958")
g = z[1]
-- returns : 0.6349999958
Well my first post and I’m not sure if it will be verified since I solved the problem in the same post, but it’s not fully solved.
If units aren’t in meters then what? I’ll have to get units and filter string accordingly?
Is there a better way?
Max understands the suffix m as minutes.
so 1m, assuming 30fps, is 1800 frames.
Filterstring is a little much. You can use trimRight <value> “m” instead.
units.formatValue returns a string value of the float in the current units. in our case it’s meters.
but “as float” method doesn’t know that and thinks that it’s minutes.
the right way to convert float value in generic units to meters is:
value / (units.decodevalue "1m")
-----------
123. / (units.decodevalue "1m")
3.1242
units.decodevalue "3.1242m"
123.0