Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting a float to a string

Status
Not open for further replies.

timmay3141

Programmer
Dec 3, 2002
468
US
How can I convert a float to a string? I could convert an int to a string via itoa, but no ftoi exists. Any thoughts?
 
Check the MSDN documentation on sprintf.

CString::Format should also work.
 
Or even check the _fcvt function in msdn.

_fcvt : Converts a floating-point number to a string.
 
you can use the function "sprintf" do it.
here is an example:
Code:
char str[20] = {0};
float num = 7.9f;
sprintf( str, "%f", num );
 

... or try

std::string ftoa ( float f )

as a more modern way.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top