SteveNi Posted September 19, 2016 Share Posted September 19, 2016 Hi So basically I have a certain float value, lets say 3.68, and I want to get the digits before the comma (there are no functions that rounds to the lowest integer), so that I can later use that in some math operations. I know I can use split() to split to the point, and sprintf() to convert to string, but I cant get this last function to work, for example if I wrote float _x = sprintf("%g",3.68); But this gives me an error... Anyone knows how to convert to string and back to the original variable type? Thanks Quote Link to comment Share on other sites More sharing options...
MrScienceOfficer Posted September 19, 2016 Share Posted September 19, 2016 18 minutes ago, SteveNi said: (there are no functions that rounds to the lowest integer) I may be misunderstanding you, but I think what your looking for is floor(). https://www.sidefx.com/docs/houdini15.5/vex/functions/floor Quote Link to comment Share on other sites More sharing options...
fsimerey Posted September 19, 2016 Share Posted September 19, 2016 I think MrScienceOfficer give you what you are looking for. BTW, to convert float to string and string to float, etc...: itoa: https://www.sidefx.com/docs/houdini15.5/vex/functions/itoa atoi: https://www.sidefx.com/docs/houdini15.5/vex/functions/atoi atof: https://www.sidefx.com/docs/houdini15.5/vex/functions/atof Quote Link to comment Share on other sites More sharing options...
SteveNi Posted September 20, 2016 Author Share Posted September 20, 2016 Awesome!! I didnt know those functions... Also I was searching for a function to round to the larger integer but I managed to do that by doing this thing on the number I need to round: Example with 2.81: 2.81 + (1- (2.81%1)) Thanks a lot Quote Link to comment Share on other sites More sharing options...
davpe Posted September 20, 2016 Share Posted September 20, 2016 to round to the larger int try ceil() Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.