At first I used boost's lexical_cast
to do this. But due to the way C++ represents doubles/floats, when I converted 5.1
to a string it would give me 5.0999999
or something to that extent. So, I converted it this way:
stringstream ss;
ss << 3.14159265359;
cout << ss.str();
But this would only give me 3.14159
, and I would like more precision than that. I think I saw something about printf()
being able to do this, but I am actually working on a Windows GUI program, not outputting to a console. How can I get more than 5 decimal digits of precision? I am willing to settle for 8, but 10 or 11 would be nice. Is this too much to ask for given how C++ represents floats and doubles?