I\' d like to use lexical_cast to convert a float to a string. Usually it works fine, but I have some problems with numbers without decimal. How can I fix numbe
lexical_cast
If you need complex formatting, use std::ostringstream instead. boost::lexical_cast is meant for "simple formatting".
std::ostringstream
boost::lexical_cast
std::string get_formatted_value(double d) { std::ostringstream oss; oss.setprecision(3); oss.setf(std::ostringstream::showpoint); oss << d; return oss.str(); }