I want to do some calculations, and I want the result to be correct to decimal places, say 12. So I wrote a sample:
#define PI 3.1415926535897932384626433832795028841971693993751 double d, k, h; k = 999999/(2*PI); h = 999999; d = PI*k*k*h; printf("%.12f\n", d);
But it gives the result:
79577232813771760.000000000000
I even used setprecision (), but the same answer is more likely in exponential form.
cout<<setprecision(12)<<d<<endl;
prints
7.95772328138e+16
Used a long double, but in vain.
Now is there any way besides storing the integer part and fractional part separately in long long types?
If so, what can be done to get an answer for sure?
Sunny source share