-1

I don't need to do any calculations just print out the numbers.

double n1 = 1000000.5985;
double n2 = 9999999.0;
double n3 = 678300.893;

When I try

cout << n1 << n2 << n3;

I get 1e+006 1e+007 678301

How do I get it to print the whole number without converting to a string?

  • 5
    Does this answer your question? [How do I print a double value with full precision using cout?](https://stackoverflow.com/questions/554063/how-do-i-print-a-double-value-with-full-precision-using-cout) – Minh Nov 02 '20 at 06:54

1 Answers1

0

Use setprecision() from <iomanip>.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
   double f = 1000000.5985;
   cout << f << endl;
   cout << fixed << setprecision(6) << f <<endl;
   cout << fixed << setprecision(5) << f << endl;
   cout << fixed << setprecision(9) << f << endl;
   return 0;
}

Output is

1e+06
1000000.598500
1000000.59850
1000000.598500000
swag2198
  • 2,546
  • 1
  • 7
  • 18