I defined a variable as long double
to use the maximum precision of number PI
, but when the program gets excecuted, the value of the variable changed to 3.141592653589793116
and lost some precision.
I checked the size of variable , it is same as size of double so that works like double.
I have problem to store this value, not for print that. Now , how can I use long double
with full precision?
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
//number PI
long double pi = 3.14159265358979323846264338327950;
int sz1 = sizeof(long double);
int sz2 = sizeof(pi);
cout << sz1 << endl;
cout << sz2 << endl;
printf_s("%.20f\n", pi);
cout << setprecision(20) << pi;
return 0;
}
//results:
8
8
3.141592653589793116
3.141592653589793116