Thursday, September 24, 2009

print more numbers for "cout"

Normally for double data, the precision is quite high. But when you want to show some data like "123456789.12345", it just show you "1.2356e+09". From that, we see it just show you the data with 5 precision. In fact, it does not lose any data. This is for easy to see. If you want to show more, you can do:


double a=123456789.12345;
int n=14;
cout << setprecision(n) << a << endl;

This time it shows you "123456789.12345".

No comments: