Float
#include <stdafx.h>
#include <iostream>
using namespace std;
int main()
{
/* Floating point numbers are stored in 32 bits.Default type for floating point number is double.
If we output a number that is large enough, or has enough decimal places, it will be printed in scientific notation. */
cout<< "Scientific notation of floating point numbers: "<< endl;
double value = 1000000.0;
cout << value << endl;
value = 0.00001;
cout << value << endl<< endl;
/*When outputting floating point numbers cout assumes all variables are only significant to 6 digits,
and hence it will truncate anything after that. */
cout<< "displaying only 6 digits:" << endl;
float number;
number = 1.55555555f;
cout << number << endl;
number = 111.5555555555f;
cout << number << endl;
number = 111111.55555f;
cout << number << endl;
return 0;
}
Output:
Scientific notation of floating point numbers:
1e+006
1e-005
displaying only 6 digits:
1.55556
111.556
111112