Jump to content

VEX - converting ints and floats to strings


SteveNi

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...