, , , standard iostream ++. , : -
printf ("%f\n", d2);
std::cout, std::setprecision, %g %f printf. : -
std::cout << std::setprecision(10) << "value2: " << d2 << std::endl;
But if you do not like this method and you use C ++ 11 (& onwards), you can also write: -
std::cout << "value2: " << std::to_string(d2) << std::endl;
This will give you the same result as printf ("%f\n", d2);.
A much better method is to undo the rounding that occurs in std::coutusing std::fixed: -
#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::fixed;
double d = 123456.789;
std::cout << d;
return 0;
}
Exit: -
123456.789000
So, I think your problem is resolved.
source
share