double precision confusion

Hello everyone

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>

using namespace std;

int main(){

    double PI = atan2(0.0f, -1.0f);
    cout << PI << endl;
}


My thanks in advance for any help offered.

Regards
Nikki
Hi Ishtar,

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.

Thanx
Last edited on
Hi Rajroshi

Many thanks for your help. This did indeed fix my problem :)

Topic archived. No new replies allowed.