expression q: rasterize float to n number of fract digits

   4733   5   2
User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
Hi,

I don't know if I'm overseeing something very obvious here - sorry, if that would be the case…

How can I “rasterize” a float to have only a given number of fractional digits?

What I mean is an expression like (desired result is 9.12):
xx(2, 9.123456)

Is there something already available? Or do I have to build a function myself?

Thanks,
Marc
User Avatar
Member
36 posts
Joined: Oct. 2011
Offline
unfortunately, no…

it seems python also don't have such a built-in function.

my solution is floor(9.123456*(10**2))/(10**2), i hope someone can offer a better solution
User Avatar
Member
1621 posts
Joined: March 2009
Offline
There is nothing better, even though most people do it with “trunc”

trunc(315.34543435*100)/100

(but that's basically the same thing)
Martin Winkler
money man at Alarmstart Germany
User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
Thanks for your input. That will do it for now…

Do you know any resources about how I can add new functions to houdini's scripting language, permanently and/or for the current hip-file only? I always wanted to extend it a little, but don't know where to start.

Cheers
User Avatar
Member
4515 posts
Joined: Feb. 2012
Offline
You can use exread to read your custom hscript expressions:
http://www.sidefx.com/docs/houdini12.5/commands/exread [sidefx.com]
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | animatrix2k7.gumroad.com
User Avatar
Member
205 posts
Joined: Dec. 2009
Offline
Thanks!
  • Quick Links