I need help on keeping the precision of a double. If I assign a literal to a double, the actual value was truncated.
double
int main() { double x =
You must use setiosflags(ios::fixed) and setprecision(x).
setiosflags(ios::fixed)
setprecision(x)
For example, cout << setiosflags(ios::fixed) << setprecision(4) << myNumber << endl;
cout << setiosflags(ios::fixed) << setprecision(4) << myNumber << endl;
Also, don't forget to #include .
#include