I am learning c++ in school but cant figure this one out. I am pretty sure it is float vs double but not sure. What I want to know is why the output is different with a float and double. I know floats are smaller then doubles but not sure why the output of this problem is diff. Here is the code:
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setprecision;
const double PI = 3.14159265358979;
int main()
{
const float PI = static_cast< float > ( :
I );
cout << setprecision[ 20 )
<< " Local float value of PI = " << PI
<< "\nGlobal double value of PI = " << :
I << endl;
return 0;
}
The output in Microsoft Visual c++ is :
Local float value of PI = 3.1415927410125732
Global double value of PI = 3.14159265358979
Why is the output different? Is it the cast operator, or the float? Any help is much appreciated. Thanks
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::setprecision;
const double PI = 3.14159265358979;
int main()
{
const float PI = static_cast< float > ( :
cout << setprecision[ 20 )
<< " Local float value of PI = " << PI
<< "\nGlobal double value of PI = " << :
return 0;
}
The output in Microsoft Visual c++ is :
Local float value of PI = 3.1415927410125732
Global double value of PI = 3.14159265358979
Why is the output different? Is it the cast operator, or the float? Any help is much appreciated. Thanks