This question already has an answer here:
- The precision of std::to_string(double) 2 answers
In C++11, std::to_string defaults to 6 decimal places when given an input value of type float
or double
. What is the recommended, or most elegant, method for changing this precision?
There is no way to change the precision via
to_string()
but thesetprecision
IO manipulator could be used instead: