Round off to third decimal places
9120 8 1- kazurati
- Member
- 27 posts
- Joined: 10月 2018
- Offline
- BabaJ
- Member
- 2127 posts
- Joined: 9月 2015
- Offline
It's better if you post a hip file with a clear description of what you want to apply the result too.
As it is floating point values you are dealing with - it has ‘nothing’ to do with Houdini per se.
It is the nature of using computer hardware.
You may want to do some of your own research first like as one example here:
https://blog.penjee.com/what-are-floating-point-errors-answered/ [blog.penjee.com]
So posting your hip and what you want to accomplish, someone might be able to help you determine if what you have could be a problem or not.
If so, what you might be able to do.
As it is floating point values you are dealing with - it has ‘nothing’ to do with Houdini per se.
It is the nature of using computer hardware.
You may want to do some of your own research first like as one example here:
https://blog.penjee.com/what-are-floating-point-errors-answered/ [blog.penjee.com]
So posting your hip and what you want to accomplish, someone might be able to help you determine if what you have could be a problem or not.
If so, what you might be able to do.
- sburke
- Member
- 9 posts
- Joined: 9月 2017
- Offline
- Konstantin Magnus
- Member
- 682 posts
- Joined: 9月 2013
- Online
Hi kazurati,
this works for me on all sorts of random values:
eg:
0.380973 -> 380.0 -> 0.38
this works for me on all sorts of random values:
f@num_rand = rand(@Frame); f@num_thsd = floor(@num_rand * 1000); f@num_clip = @num_thsd / 1000.0;
eg:
0.380973 -> 380.0 -> 0.38
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
- kazurati
- Member
- 27 posts
- Joined: 10月 2018
- Offline
- tamte
- Member
- 8786 posts
- Joined: 7月 2007
- Offline
as mentioned previously, it's has to do with floating point precision
even if you do: f@target = 0.998;
you will see that the Font SOP will still print something else, like: 0.99800002574920654
it's because it can't represent 0.998 precisely as a floating point number
so you'll need to format your floating point number into a string using sprintf() for example
even if you do: f@target = 0.998;
you will see that the Font SOP will still print something else, like: 0.99800002574920654
it's because it can't represent 0.998 precisely as a floating point number
so you'll need to format your floating point number into a string using sprintf() for example
Tomas Slancik
FX Supervisor
Method Studios, NY
FX Supervisor
Method Studios, NY
- mujuningaiza
- Member
- 5 posts
- Joined: 9月 2018
- Offline
tamte
as mentioned previously, it's has to do with floating point precision
even if you do: f@target = 0.998;
you will see that the Font SOP will still print something else, like: 0.99800002574920654
it's because it can't represent 0.998 precisely as a floating point number
so you'll need to format your floating point number into a string using sprintf() for example
From Tomas attachment there's some function & argument am not familiar with, so incase someone is struggling as I was
When you use
sprint("%f", floatValue);
This work whether you type hard core floats or you're using chf values.
When you want to trim decimal places like 1 or 2 or 3 decimal place you will have to write like
sprint("%.2f", floatValue);
Hopefully this will be helpful as well.
Edited by mujuningaiza - 2022年12月13日 11:08:03
- jsmack
- Member
- 8041 posts
- Joined: 9月 2011
- Offline
- mujuningaiza
- Member
- 5 posts
- Joined: 9月 2018
- Offline
jsmack
Assuming adding a layer of vex to convert from float to string is a pain, the ftrim() expression can be used to pretty print floats as strings.ftrim(detail(-1, "test", 0))
Thanks @jsmack for showing me how to use ftrim expression this is helpful, although I can't trim to how many decimals I want. Although with
sprint("%.3f", 0.7838759687)
I believe adding
sprintf
Edited by mujuningaiza - 2022年12月14日 05:10:02
-
- Quick Links