Apr 28, 2003 #1 timmay3141 Programmer Joined Dec 3, 2002 Messages 468 Location 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?
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?
Apr 28, 2003 #2 markharr Vendor Joined May 21, 2001 Messages 87 Location AU Check the MSDN documentation on sprintf. CString::Format should also work. Upvote 0 Downvote
Apr 29, 2003 #3 PerFnurt Programmer Joined Feb 25, 2003 Messages 972 Location SE Or even check the _fcvt function in msdn. _fcvt : Converts a floating-point number to a string. Upvote 0 Downvote
Apr 29, 2003 #4 Leibnitz Programmer Joined Apr 6, 2001 Messages 393 Location CA 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 ); Upvote 0 Downvote
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 );
Apr 29, 2003 #5 rossno Programmer Joined Feb 8, 2002 Messages 46 Location US ... or try std::string ftoa ( float f ) as a more modern way. Upvote 0 Downvote
Apr 29, 2003 #6 chipperMDW Programmer Joined Mar 24, 2002 Messages 1,268 Location US Or std::stringstream, supported by the C++ Standard. Or boost::lexical_cast, a convenient wrapper around that use of std::stringstream (http://www.boost.org). Upvote 0 Downvote
Or std::stringstream, supported by the C++ Standard. Or boost::lexical_cast, a convenient wrapper around that use of std::stringstream (http://www.boost.org).