Floats to strings

Started by
2 comments, last by _elf_ 16 years, 5 months ago
Hi there, I need a way to convert a float to a string. I'm using C++ with Vis Stud 2005, and am using the MFC. It's for a calculator, so the size will need to be limited. A dot will always be the decimal seperator. Thanks very much
Advertisement
#include <sstream>ostringstream buffer;float f = 4.5;buffer << f;string str = buffer.str();
float number = 123.456;string str = string.format( "%f", number );
You can use function _fcvt. For more information use this link (ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vccrt/html/74584c88-f0dd-4907-8fca-52da5df583f5.htm) in help.

This topic is closed to new replies.

Advertisement