Sign in to follow this  
HarrisonPloeg

converting from char to float and float to char

Recommended Posts

hii..
To convert from float to char use the function fcvt
ex.
char *fps=NULL;
int dec,sign;
float LastFrameRate = 12.33f

fps=_fcvt(LastFrameRate,2,&dec,&sign);

The number 2 specifies the number of digits after the decimal point.dont worry about the last 2 parameters..

just in case u need to convert from integer to char..its itoa and from char to integer its atoi...

hope this helps...

Share this post


Link to post
Share on other sites
Unless you are using C++, in which case use strings and stringstreams:


#include <sstream>

float str_to_float(const std::string &in) // you can still pass a const char* to this
{
std::ostringstream o(in); float f; o >> f; return f;
}

std::string float_to_str(float f)
{
std::istringstream i; i << f; return i.str();
}


Or you could not reinvent this particular wheel, and use boost::lexical_cast.

Share this post


Link to post
Share on other sites
First tell me what you think a char is. Note that a char is not the same thing as an array of char. Also, an array of char is not "a string", in a useful sense - if you're thinking of strings, you should be using real strings.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this