I am calculating square root of 2147483647 by sqrt function.and the result must be a float value 46340.95 but my code returns the value 46341.
Can anyone tell me where is the problem?
i am using code :
double x=2147483647.0;
double y=sqrt(x);
cout<< y;
I get that same result. But, if I inject a
setprecision, I get the right value:gives me:
In fact, if you use the folowing code:
you get:
So it appears that the default setting (at least for my environment) is a precision of zero.
If you want a specific format, I suggest you explicitly request it.