Use cout's precision function to set the precision to an arbitrary length. Here I used the maximum precision of a double float from the <limits> library. When I print the value, I tell cout to use the specified precision by passing it the fixed specifier.#include <iostream>
#include <limits>using namespace std;
typedef numeric_limits<double> dbl;
int main()
{
double d = 3.14159265358979;
cout.precision(dbl::digits10);
cout << "Pi: " << fixed << d << endl;
return 0;
}
Compile and run the snippet above and you should see the following output.
$ ./a.out
Pi: 3.141592653589790
No comments:
Post a Comment