My program needs to accurately average various angles, to do this I need to express PI to at least 8 decimal places. The following code should express PI to a good precision but the output is:
3.14159
Why is my double being rounded to 5 decimal places?
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
#include <cmath>
usingnamespace std;
int main(){
double PI = atan2(0.0f, -1.0f);
cout << PI << endl;
}
Technically double grant you the 10 significant digits. it means 123456789.1 or 12345678.12
or 1.123456789 although in my computer I am getting 52 digits.
But the precision of cout precision is not allowing this. So we can use
cout <<setprecision(52);
to get the full double precision.
include <iomanip> also.