float

Nov 17, 2012 at 2:13pm
after run program

#include "iostream"

using namespace std;

int main()
{
float a = 10254158.3454;
cout << a;

system("pause");
return 0;
}
/*
result :: 1.02542e+007
*/
How do I view the data in the following form.
result :: 10254158.3454
Last edited on Nov 17, 2012 at 2:14pm
Nov 17, 2012 at 2:23pm
you can modifiy the precision of the output (i.e. the printed digits) with a call to cout.precision(16). However, if you're using float as the data type you will get an incorrect result, since float has only 7 significant digits in decimal system. If you want better precision (10254158.3454 contains 12 digits) you should use double or maybe even long double.
Last edited on Nov 17, 2012 at 2:25pm
Topic archived. No new replies allowed.