precision of float and double

int main()
{
using namespace std;
float a = 2.34E+22f;
float b = a + 1.0f;


cout << "a = " << a << endl;
cout << "b - a = " << b - a << endl;


cin.get();
cin.get();
return 0;
}


int main()
{
using namespace std;
cout.setf(ios_base::fixed, ios_base::floatfield); //fixed point


float tub = 10.0f / 3.0f;
double mint = 10.0 / 3.0;
const float million = 1.0e6;


cout << "tub = " << tub;
cout << ", a million tubs = " << million * tub;
cout << ", \nand ten million tubs = " << 10 * million * tub <<endl;


cout << "mint = " << mint << " and a million mints = " << million * mint << endl;


cin.get();
cin.get();
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326164297&siteId=291194637