
30 Apr
2009
30 Apr
'09
5:20 p.m.
Grant Birchmeier:
I'm seeing unexpected behavior when using lexical_cast<string>.
This code: const float f = 00123.12300; cout << f << endl; cout << boost::lexical_caststd::string(f) << endl; gives the result: 123.123 123.123001
Two questions:
(1) Is there a way to eliminate this trailing '1' with lexical_cast (presumably some wierd rounding error)?
Try this code: float f = 00123.12300; std::cout << f << std::endl; std::cout << boost::lexical_caststd::string(f) << std::endl; float f2 = 123.123001; std::cout << f2 << std::endl; std::cout << boost::lexical_caststd::string(f2) << std::endl; std::cout << f - f2 << std::endl; which will hopefully answer your question.