I am using C++11. I have real world coordinates such as 38.0098662, 23.7805398
in a text file, meaning 2 double
variables. I parse that file with C++ and I convert the strings
to double
with the stod()
method. When I tried printing the values with count.precision(9);
, the values seemed to be the same as in the text file.
Then, I want to convert those double
values back to string
format. For that I use to_string()
method. However that seems to be changing the value slightly. For example:
38.0098662, 23.7805398 became
38.009866, 23.780540
// in fact, every number is xx.yyyyyy
I don't understand why this is so hard to do with C++11. Why do I lose precision for no reason ? How can I do this properly ? Every question I looked into pointed to to_string()
method, which is what I am using.