-
March 14th, 2012, 04:26 AM
#1
Converting integers into floats
Just a quick question I've long forgotten, is that how do you convert integers into floats
I remember there is something like ftoi, I am looking into something handy like the std
Thanks
Jack
-
March 14th, 2012, 04:44 AM
#2
Re: Converting integers into floats
You could use a static_cast or add 0.0f
-
March 14th, 2012, 06:02 AM
#3
Re: Converting integers into floats
Originally Posted by lucky6969b
Just a quick question I've long forgotten, is that how do you convert integers into floats
Doesn't assignment operator work?
Or a simple C-casting?
Victor Nijegorodov
-
March 14th, 2012, 07:22 AM
#4
Re: Converting integers into floats
Do you need rounding or truncation?
EDIT: Sorry, pointless question I was thinking float to int
Last edited by JohnW@Wessex; March 15th, 2012 at 04:00 AM.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
March 14th, 2012, 12:01 PM
#5
Re: Converting integers into floats
static_cast we generally use for this. Well there can be multiple choice to do this as suggested in earlier posts
regards,
Vatsa
www.objectiveprogramming.com
-
March 14th, 2012, 01:47 PM
#6
Re: Converting integers into floats
Code:
int i = 5;
float f = i;
All you should have to do is that. The compiler might warn you about the implicit conversion, but it should work.
-
March 16th, 2012, 01:39 AM
#7
Re: Converting integers into floats
Thanks guys, i've found a solution
f = static_cast<float>(i);
Have a nice day!!
Jack
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|